-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Praesidiarius
committed
Feb 7, 2020
1 parent
cf8a185
commit 2dc414b
Showing
9 changed files
with
345 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Address.php - Address Entity | ||
* | ||
* Entity Model for Contact Address | ||
* | ||
* @category Model | ||
* @package Contact\Address | ||
* @author Verein onePlace | ||
* @copyright (C) 2020 Verein onePlace <[email protected]> | ||
* @license https://opensource.org/licenses/BSD-3-Clause | ||
* @version 1.0.0 | ||
* @since 1.0.0 | ||
*/ | ||
|
||
namespace OnePlace\Contact\Address\Model; | ||
|
||
use Application\Model\CoreEntityModel; | ||
|
||
class Address extends CoreEntityModel { | ||
/** | ||
* Contact constructor. | ||
* | ||
* @param AdapterInterface $oDbAdapter | ||
* @since 1.0.0 | ||
*/ | ||
public function __construct($oDbAdapter) { | ||
parent::__construct($oDbAdapter); | ||
|
||
# Set Single Form Name | ||
$this->sSingleForm = 'contactaddress-single'; | ||
|
||
# Attach Dynamic Fields to Entity Model | ||
$this->attachDynamicFields(); | ||
} | ||
|
||
/** | ||
* Set Entity Data based on Data given | ||
* | ||
* @param array $aData | ||
* @since 1.0.0 | ||
*/ | ||
public function exchangeArray(array $aData) { | ||
$this->id = !empty($aData['Address_ID']) ? $aData['Address_ID'] : 0; | ||
|
||
$this->updateDynamicFields($aData); | ||
} | ||
|
||
public function getLabel() { | ||
return $this->street; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
/** | ||
* AddressTable.php - Address Table | ||
* | ||
* Table Model for Contact Address | ||
* | ||
* @category Model | ||
* @package Contact\Address | ||
* @author Verein onePlace | ||
* @copyright (C) 2020 Verein onePlace <[email protected]> | ||
* @license https://opensource.org/licenses/BSD-3-Clause | ||
* @version 1.0.0 | ||
* @since 1.0.0 | ||
*/ | ||
|
||
namespace OnePlace\Contact\Address\Model; | ||
|
||
use Application\Controller\CoreController; | ||
use Application\Model\CoreEntityTable; | ||
use Laminas\Db\TableGateway\TableGateway; | ||
use Laminas\Db\ResultSet\ResultSet; | ||
use Laminas\Db\Sql\Select; | ||
use Laminas\Db\Sql\Where; | ||
use Laminas\Paginator\Paginator; | ||
use Laminas\Paginator\Adapter\DbSelect; | ||
|
||
class AddressTable extends CoreEntityTable { | ||
|
||
/** | ||
* AddressTable constructor. | ||
* | ||
* @param TableGateway $tableGateway | ||
* @since 1.0.0 | ||
*/ | ||
public function __construct(TableGateway $tableGateway) { | ||
parent::__construct($tableGateway); | ||
|
||
# Set Single Form Name | ||
$this->sSingleForm = 'contactaddress-single'; | ||
} | ||
|
||
/** | ||
* Get Contact Entity | ||
* | ||
* @param int $id | ||
* @return mixed | ||
* @since 1.0.0 | ||
*/ | ||
public function getSingle($id) { | ||
# Use core function | ||
return $this->getSingleEntity($id,'Address_ID'); | ||
} | ||
|
||
/** | ||
* Save Contact Entity | ||
* | ||
* @param Contact $oContact | ||
* @return int Contact ID | ||
* @since 1.0.0 | ||
*/ | ||
public function saveSingle(Address $oContact) { | ||
$aData = []; | ||
|
||
$aData = $this->attachDynamicFields($aData,$oContact); | ||
|
||
$id = (int) $oContact->id; | ||
|
||
if ($id === 0) { | ||
# Add Metadata | ||
$aData['created_by'] = CoreController::$oSession->oUser->getID(); | ||
$aData['created_date'] = date('Y-m-d H:i:s',time()); | ||
$aData['modified_by'] = CoreController::$oSession->oUser->getID(); | ||
$aData['modified_date'] = date('Y-m-d H:i:s',time()); | ||
|
||
echo 'save new address'; | ||
# Insert Contact | ||
$this->oTableGateway->insert($aData); | ||
|
||
# Return ID | ||
return $this->oTableGateway->lastInsertValue; | ||
} | ||
|
||
# Check if Contact Entity already exists | ||
try { | ||
$this->getSingle($id); | ||
} catch (\RuntimeException $e) { | ||
throw new \RuntimeException(sprintf( | ||
'Cannot update Address with identifier %d; does not exist', | ||
$id | ||
)); | ||
} | ||
|
||
# Update Metadata | ||
$aData['modified_by'] = CoreController::$oSession->oUser->getID(); | ||
$aData['modified_date'] = date('Y-m-d H:i:s',time()); | ||
|
||
# Update Contact | ||
$this->oTableGateway->update($aData, ['Address_ID' => $id]); | ||
|
||
return $id; | ||
} | ||
|
||
/** | ||
* Generate new single Entity | ||
* | ||
* @return Contact | ||
* @since 1.0.0 | ||
*/ | ||
public function generateNew() { | ||
return new Address($this->oTableGateway->getAdapter()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
<?php | ||
use Application\Controller\CoreController; | ||
use OnePlace\Contact\Address\Model\AddressTable; | ||
|
||
$oForm = CoreController::$aCoreTables['core-form']->select(['form_key'=>'contactaddress-single']); | ||
if(count($oForm) > 0) { | ||
$aFields = [ | ||
'address-base' => CoreController::$aCoreTables['core-form-field']->select(['form'=>'contactaddress-single']), | ||
]; | ||
?> | ||
<?= $this->partial('partial/basicformfields', ['sFormName'=>'contactaddress-single','sTab'=>'address-base','aFieldsByTab'=>$aFields]); ?> | ||
<?php | ||
} else { | ||
echo 'Could not load address form'; | ||
} | ||
?> | ||
<h2>Add Address</h2> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,34 @@ | ||
<?php | ||
use Application\Controller\CoreController; | ||
use OnePlace\Contact\Address\Model\AddressTable; | ||
|
||
$oForm = CoreController::$aCoreTables['core-form']->select(['form_key'=>'contactaddress-single']); | ||
if(count($oForm) > 0) { | ||
$oAddressTbl = CoreController::$oServiceManager->get(AddressTable::class); | ||
|
||
$oAddresses = $oAddressTbl->fetchAll(false,['contact_idfs'=>$oItem->getID()]); | ||
$oPrimaryAddress = false; | ||
if(count($oAddresses) > 0) { | ||
foreach($oAddresses as $oAddr) { | ||
$oPrimaryAddress = $oAddr; | ||
break; | ||
} | ||
} | ||
|
||
$aFields = [ | ||
'address-base' => CoreController::$aCoreTables['core-form-field']->select(['form'=>'contactaddress-single']), | ||
]; | ||
|
||
$aPartialData = ['sFormName'=>'contactaddress-single','sTab'=>'address-base','aFieldsByTab'=>$aFields]; | ||
if($oPrimaryAddress) { | ||
$aPartialData['oItem'] = $oPrimaryAddress; | ||
?> | ||
<input type="hidden" name="contactaddress-single_address_primary_id" value="<?=$oPrimaryAddress->getID()?>" /> | ||
<?php } ?> | ||
<?= $this->partial('partial/basicformfields', $aPartialData); ?> | ||
<?php | ||
} else { | ||
echo 'Could not load address form'; | ||
} | ||
?> | ||
<h2>Edit Address</h2> | ||
|
Oops, something went wrong.