Skip to content

Commit

Permalink
basic view tab working
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Feb 8, 2020
1 parent 0ff1f63 commit a30e120
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 6 deletions.
3 changes: 2 additions & 1 deletion data/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ INSERT INTO `core_form_tab` (`Tab_ID`, `form`, `title`, `subtitle`, `icon`, `cou
-- Add new partial
--
INSERT INTO `core_form_field` (`Field_ID`, `type`, `label`, `fieldkey`, `tab`, `form`, `class`, `url_view`, `url_list`, `show_widget_left`, `allow_clear`, `readonly`, `tbl_cached_name`, `tbl_class`, `tbl_permission`) VALUES
(NULL, 'partial', 'Contact', 'basket_contact', 'basket-contact', 'basket-single', 'col-md-12', '', '', '0', '1', '0', '', '', '');
(NULL, 'partial', 'Contact', 'basket_contact', 'basket-contact', 'basket-single', 'col-md-12', '', '', '0', '1', '0', '', '', ''),
(NULL, 'hidden', 'Contact', 'contact_idfs', 'basket-base', 'basket-single', 'col-md-3', '', '', '0', '1', '0', '', '', '');
51 changes: 51 additions & 0 deletions src/Controller/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OnePlace\Basket\Model\BasketTable;
use Laminas\View\Model\ViewModel;
use Laminas\Db\Adapter\AdapterInterface;
use OnePlace\Contact\Model\ContactTable;

class ContactController extends CoreEntityController {
/**
Expand Down Expand Up @@ -51,4 +52,54 @@ public function __construct(AdapterInterface $oDbAdapter, BasketTable $oTableGat
}
}
}

public function attachContact($oBasket) {
$oContact = false;
if($oBasket->contact_idfs != 0) {
try {
$oContactTbl = CoreEntityController::$oServiceManager->get(ContactTable::class);
} catch(\RuntimeException $e) {

}

if(isset($oContactTbl)) {
$oContact = $oContactTbl->getSingle($oBasket->contact_idfs);
try {
$oAddressTbl = CoreEntityController::$oServiceManager->get(\OnePlace\Contact\Address\Model\AddressTable::class);
} catch(\RuntimeException $e) {

}
if(isset($oAddressTbl)) {
$oAddresses = $oAddressTbl->fetchAll(false,['contact_idfs'=>$oContact->getID()]);
$oContact->oAddresses = $oAddresses;
}
}
}

$aFields = [];
$aUserFields = CoreEntityController::$oSession->oUser->getMyFormFields();
if(array_key_exists('contact-single',$aUserFields)) {
$aFieldsTmp = $aUserFields['contact-single'];
if(count($aFieldsTmp) > 0) {
# add all contact-base fields
foreach($aFieldsTmp as $oField) {
if($oField->tab == 'contact-base') {
$aFields[] = $oField;
}
}
}
}

# Pass Data to View - which will pass it to our partial
return [
# must be named aPartialExtraData
'aPartialExtraData' => [
# must be name of your partial
'basket_contact'=> [
'oContact'=>$oContact,
'aFields'=>$aFields,
]
]
];
}
}
7 changes: 4 additions & 3 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Laminas\EventManager\EventInterface as Event;
use Laminas\ModuleManager\ModuleManager;
use OnePlace\Basket\Model\BasketTable;
use OnePlace\Basket\Contact\Controller\ContactController;

class Module {
/**
Expand All @@ -47,11 +48,11 @@ public function onBootstrap(Event $e)
// This method is called once the MVC bootstrapping is complete
$application = $e->getApplication();
$container = $application->getServiceManager();
//$oDbAdapter = $container->get(AdapterInterface::class);
//$tableGateway = $container->get(BasketTable::class);
$oDbAdapter = $container->get(AdapterInterface::class);
$tableGateway = $container->get(BasketTable::class);

# Register Filter Plugin Hook
//CoreEntityController::addHook('contact-view-before',(object)['sFunction'=>'attachContactForm','oItem'=>new ContactController($oDbAdapter,$tableGateway,$container)]);
CoreEntityController::addHook('basket-view-before',(object)['sFunction'=>'attachContact','oItem'=>new ContactController($oDbAdapter,$tableGateway,$container)]);
//CoreEntityController::addHook('contacthistory-add-before-save',(object)['sFunction'=>'attachContactToBasket','oItem'=>new ContactController($oDbAdapter,$tableGateway,$container)]);
}

Expand Down
2 changes: 1 addition & 1 deletion view/partial/basket_contact-add.phtml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php
<?php
2 changes: 1 addition & 1 deletion view/partial/basket_contact-edit.phtml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php
<?php
47 changes: 47 additions & 0 deletions view/partial/basket_contact-view.phtml
Original file line number Diff line number Diff line change
@@ -1 +1,48 @@
<?php
# Only show partial if data is set
if(array_key_exists('basket_contact',$this->aPartialData)) {
# add address form fields
$oContact = $this->aPartialData['basket_contact']['oContact'];
$aFields = $this->aPartialData['basket_contact']['aFields'];
if($oContact) {
$aFieldsByTab = ['contact-base'=>$aFields];
$sName = $oContact->getTextField('firstname').' '.$oContact->getTextField('lastname');
if($oContact->getSelectFieldID('title_idfs') != 0) {
$sName = $oContact->getSelectField('title_idfs')->tag_value.' '.$sName;
}
if($oContact->getSelectFieldID('salutation_idfs') != 0) {
$sName = $oContact->getSelectField('salutation_idfs')->tag_value.' '.$sName;
}
?>
<div class="row">
<div class="col-md-12">
<i class="fas fa-user"></i> <?=$sName?><br/>
<hr/>
<i class="fas fa-envelope"></i> <?=($oContact->getTextField('email')) ? $oContact->getTextField('email') : '-'?><br/>
<i class="fas fa-phone"></i> <?=($oContact->getTextField('phone')) ? $oContact->getTextField('phone') : '-'?><br/>
<hr/>
<?php
if(isset($oContact->oAddresses)) {
if(count($oContact->oAddresses) > 0) {
foreach($oContact->oAddresses as $oAddr) { ?>
<i class="fas fa-home"></i> <?=($oAddr->getTextField('street')) ? $oAddr->getTextField('street') : ''?><br/>
<?=($oAddr->getTextField('zip')) ? $oAddr->getTextField('zip') : ''?> <?=($oAddr->getTextField('city')) ? $oAddr->getTextField('city') : ''?><br/>
<?php
}
}
}
?>
</div>
</div>
<?php } else { ?>
<div class="alert alert-info px-2 py-2">
<?=$this->translate('No Contact data for this basket yet')?>
</div>
<?php
}
} else { ?>
<div class="alert alert-danger px-2 py-2">
<?= $this->translate('Could not load contact data') ?>
</div>
<?php
}

0 comments on commit a30e120

Please sign in to comment.