Skip to content

Commit

Permalink
Merge pull request #2 from OnePlc/childmodel
Browse files Browse the repository at this point in the history
Childmodel + sql changes
  • Loading branch information
JBinggi authored Feb 16, 2020
2 parents e374534 + da35b3a commit 0a07894
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 74 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "oneplace/oneplace-contact",
"description": "onePlace Contact Module",
"type": "oneplace-module",
"version": "1.0.8.2",
"version": "1.0.9",
"license": "BSD-3-Clause",
"keywords": [
"laminas",
Expand Down
2 changes: 1 addition & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
'route' => '/contact/search[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
'id' => '[a-zA-Z0-9_-]+',
],
'defaults' => [
'controller' => Controller\SearchController::class,
Expand Down
12 changes: 6 additions & 6 deletions data/data_simple.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ INSERT INTO `core_form_field` (`Field_ID`, `type`, `label`, `fieldkey`, `tab`, `
(NULL, 'textarea', 'Description', 'description', 'contact-base', 'contact-single', 'col-md-12', '', '', 0, 1, 0, '', '', ''),
(NULL, 'text', 'Firstname', 'firstname', 'contact-base', 'contact-single', 'col-md-3', '/contact/view/##ID##', '', 0, 1, 0, '', '', ''),
(NULL, 'text', 'Lastname', 'lastname', 'contact-base', 'contact-single', 'col-md-3', '/contact/view/##ID##', '', 0, 1, 0, '', '', ''),
(NULL, 'email', 'E-Mail (business)', 'email_addr', 'contact-base', 'contact-single', 'col-md-3', '/contact/view/##ID##', '', 0, 1, 0, '', '', ''),
(NULL, 'text', 'Phone (business)', 'phone', 'contact-base', 'contact-single', 'col-md-3', '/contact/view/##ID##', '', 0, 1, 0, '', '', ''),
(NULL, 'email', 'E-Mail', 'email_private', 'contact-base', 'contact-single', 'col-md-3', '/contact/view/##ID##', '', 0, 1, 0, '', '', ''),
(NULL, 'text', 'Phone', 'phone_private', 'contact-base', 'contact-single', 'col-md-3', '/contact/view/##ID##', '', 0, 1, 0, '', '', ''),
(NULL, 'featuredimage', 'Featured Image', 'featured_image', 'contact-base', 'contact-single', 'col-md-3', '', '', 0, 1, 0, '', '', ''),
(NULL, 'multiselect', 'Categories', 'category_idfs', 'contact-base', 'contact-single', 'col-md-3', '', '/tag/api/list/contact-single/category', 0, 1, 0, 'entitytag-single', 'OnePlace\\Tag\\Model\\EntityTagTable', 'add-OnePlace\\Contact\\Controller\\CategoryController'),
(NULL, 'select', 'Salutation', 'salutation_idfs', 'contact-base', 'contact-single', 'col-md-3', '', '/tag/api/list/contact-single/salutation', 0, 1, 0, 'entitytag-single', 'OnePlace\\Tag\\Model\\EntityTagTable', 'add-OnePlace\\Contact\\Controller\\SalutationController'),
Expand All @@ -16,10 +16,10 @@ INSERT INTO `core_form_field` (`Field_ID`, `type`, `label`, `fieldkey`, `tab`, `
--
-- Permissions
--
INSERT IGNORE INTO `permission` (`permission_key`, `module`, `label`, `nav_label`, `nav_href`, `show_in_menu`) VALUES
('add', 'OnePlace\\Contact\\Controller\\CategoryController', 'Add Category', '', '', 0),
('add', 'OnePlace\\Contact\\Controller\\SalutationController', 'Add Salutation', '', '', 0),
('add', 'OnePlace\\Contact\\Controller\\TitleController', 'Add Title', '', '', 0);
INSERT INTO `permission` (`permission_key`, `module`, `label`, `nav_label`, `nav_href`, `show_in_menu`, `needs_globaladmin`) VALUES
('add', 'OnePlace\\Contact\\Controller\\CategoryController', 'Add Category', '', '', 0, 0),
('add', 'OnePlace\\Contact\\Controller\\SalutationController', 'Add Salutation', '', '', 0, 0),
('add', 'OnePlace\\Contact\\Controller\\TitleController', 'Add Title', '', '', 0, 0);

--
-- Custom Tags
Expand Down
21 changes: 11 additions & 10 deletions data/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ ALTER TABLE `contact`
--
-- Permissions
--
INSERT INTO `permission` (`permission_key`, `module`, `label`, `nav_label`, `nav_href`, `show_in_menu`) VALUES
('add', 'OnePlace\\Contact\\Controller\\ContactController', 'Add', '', '', 0),
('edit', 'OnePlace\\Contact\\Controller\\ContactController', 'Edit', '', '', 0),
('index', 'OnePlace\\Contact\\Controller\\ContactController', 'Index', 'Contacts', '/contact', 1),
('list', 'OnePlace\\Contact\\Controller\\ApiController', 'List', '', '', 1),
('view', 'OnePlace\\Contact\\Controller\\ContactController', 'View', '', '', 0),
('dump', 'OnePlace\\Contact\\Controller\\ExportController', 'Excel Dump', '', '', 0),
('index', 'OnePlace\\Contact\\Controller\\SearchController', 'Search', '', '', 0);
INSERT INTO `permission` (`permission_key`, `module`, `label`, `nav_label`, `nav_href`, `show_in_menu`, `needs_globaladmin`) VALUES
('add', 'OnePlace\\Contact\\Controller\\ContactController', 'Add', '', '', 0, 0),
('edit', 'OnePlace\\Contact\\Controller\\ContactController', 'Edit', '', '', 0, 0),
('index', 'OnePlace\\Contact\\Controller\\ContactController', 'Index', 'Contacts', '/contact', 1, 0),
('list', 'OnePlace\\Contact\\Controller\\ApiController', 'List', '', '', 1, 0),
('view', 'OnePlace\\Contact\\Controller\\ContactController', 'View', '', '', 0, 0),
('dump', 'OnePlace\\Contact\\Controller\\ExportController', 'Excel Dump', '', '', 0, 0),
('index', 'OnePlace\\Contact\\Controller\\SearchController', 'Search', '', '', 0, 0),
('save', 'OnePlace\\Contact\\Controller\\SearchController', 'Save Search', '', '', 0, 0);

--
-- Form
Expand All @@ -53,9 +54,9 @@ INSERT INTO `core_form_button` (`Button_ID`, `label`, `icon`, `title`, `href`, `
(NULL, 'Edit Contact', 'fas fa-edit', 'Edit Contact', '/contact/edit/##ID##', 'primary', '', 'contact-view', 'link', '', ''),
(NULL, 'Add Contact', 'fas fa-plus', 'Add Contact', '/contact/add', 'primary', '', 'contact-index', 'link', '', ''),
(NULL, 'Export Contacts', 'fas fa-file-excel', 'Export Contacts', '/contact/export', 'primary', '', 'contact-index', 'link', '', ''),
(NULL, 'Find Contacts', 'fas fa-searh', 'Find Contacts', '/contact/search', 'primary', '', 'contact-index', 'link', '', ''),
(NULL, 'Find Contacts', 'fas fa-search', 'Find Contacts', '/contact/search', 'primary', '', 'contact-index', 'link', '', ''),
(NULL, 'Export Contacts', 'fas fa-file-excel', 'Export Contacts', '#', 'primary initExcelDump', '', 'contact-search', 'link', '', ''),
(NULL, 'New Search', 'fas fa-searh', 'New Search', '/contact/search', 'primary', '', 'contact-search', 'link', '', '');
(NULL, 'New Search', 'fas fa-search', 'New Search', '/contact/search', 'primary', '', 'contact-search', 'link', '', '');

--
-- Fields
Expand Down
6 changes: 3 additions & 3 deletions data/structure_simple.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ALTER TABLE `contact` ADD `description` TEXT NOT NULL DEFAULT '' AFTER `label`,
ADD `firstname` VARCHAR(255) NOT NULL DEFAULT '' AFTER `description`,
ADD `lastname` VARCHAR(255) NOT NULL DEFAULT '' AFTER `firstname`,
ADD `email_addr` VARCHAR(255) NOT NULL DEFAULT '' AFTER `lastname`,
ADD `phone` VARCHAR(20) NOT NULL DEFAULT '' AFTER `email_addr`,
ADD `featured_image` VARCHAR(255) NOT NULL DEFAULT '' AFTER `phone`,
ADD `email_private` VARCHAR(255) NOT NULL DEFAULT '' AFTER `lastname`,
ADD `phone_private` VARCHAR(20) NOT NULL DEFAULT '' AFTER `email_private`,
ADD `featured_image` VARCHAR(255) NOT NULL DEFAULT '' AFTER `phone_private`,
ADD `salutation_idfs` INT(11) NOT NULL DEFAULT '0' AFTER `featured_image`,
ADD `title_idfs` INT(11) NOT NULL DEFAULT '0' AFTER `salutation_idfs`;
44 changes: 44 additions & 0 deletions src/Model/ChildContact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Contact.php - Contact Entity
*
* Entity Model for Contact
*
* @category Model
* @package Contact
* @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\Model;

class ChildContact extends Contact
{
/**
* Contact constructor.
*
* @param AdapterInterface $oDbAdapter
* @since 1.0.0
*/
public function __construct($oDbAdapter) {
parent::__construct($oDbAdapter);
}

/**
* Set Entity Data based on Data given
*
* @param array $aData
* @since 1.0.0
*/
public function exchangeArray(array $aData) {
if(empty($aData['label']))
$aData['label']=$aData['firstname'].' '.$aData['lastname'];

$this->id = !empty($aData['Contact_ID']) ? $aData['Contact_ID'] : 0;
$this->label = !empty($aData['label']) ? $aData['label'] : '';
$this->updateDynamicFields($aData);
}
}
1 change: 0 additions & 1 deletion src/Model/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function __construct($oDbAdapter) {
public function exchangeArray(array $aData) {
$this->id = !empty($aData['Contact_ID']) ? $aData['Contact_ID'] : 0;
$this->label = !empty($aData['label']) ? $aData['label'] : '';

$this->updateDynamicFields($aData);
}
}
4 changes: 2 additions & 2 deletions src/Model/ContactTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getSingle($id,$sKey = 'Contact_ID') {
* @return int Contact ID
* @since 1.0.0
*/
public function saveSingle(Contact $oContact) {
public function saveSingle(ChildContact $oContact) {
$aDefaultData = [
'label' => $oContact->label,
];
Expand All @@ -74,6 +74,6 @@ public function saveSingle(Contact $oContact) {
* @since 1.0.0
*/
public function generateNew() {
return new Contact($this->oTableGateway->getAdapter());
return new ChildContact($this->oTableGateway->getAdapter());
}
}
4 changes: 2 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Module {
*
* @since 1.0.0
*/
const VERSION = '1.0.8.2';
const VERSION = '1.0.9';

/**
* Load module config file
Expand All @@ -57,7 +57,7 @@ public function getServiceConfig() : array {
Model\ContactTableGateway::class => function ($container) {
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Contact($dbAdapter));
$resultSetPrototype->setArrayObjectPrototype(new Model\ChildContact($dbAdapter));
return new TableGateway('contact', $dbAdapter, null, $resultSetPrototype);
},
],
Expand Down
30 changes: 27 additions & 3 deletions view/one-place/contact/contact/index.phtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
<div class="card">
<div class="card-header">
<?= $this->partial('partial/indexheader',['sTitle'=>'Contacts']) ?>
<div class="row">
<div class="col-md-10">
<?= $this->partial('partial/indexheader',['sTitle'=>'Contacts']) ?>
</div>
<div class="col-md-2 text-right">
<select class="form-control">
<option>-- <?=$this->translate('All')?> --</option>
<?php
if (count($aSavedSearches) > 0) {
foreach($aSavedSearches as $oSearch) { ?>
<option value="<?=$oSearch->Search_ID?>">
<?=$oSearch->label?>
</option>
<?php
}
}
?>
</select>
</div>
</div>
</div>
<div class="card-body py-0">
<?= $this->partial('partial/indextable', ['sTableName'=>$sTableName,'aItems'=>$aItems]); ?>
<?= $this->partial('partial/indextable', [
'sTableName' => $sTableName,
'aItems' => $aItems,
'aFilters' => $aFilters,
'sRoute' => $sRoute
]); ?>
</div>
<div class="card-footer">
<?= $this->partial('partial/indexpager', ['aItems'=>$aItems,'sRoute'=>(isset($sRoute)) ? $sRoute : explode('-',$sTableName)[0]]); ?>
<?= $this->partial('partial/indexpager', ['aItems'=>$aItems,'sRoute'=>$sRoute]); ?>
</div>
</div>
9 changes: 3 additions & 6 deletions view/one-place/contact/install/checkdb.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
<?=$this->translate('Database needs update. Please choose config')?>
</div>
<?php
if(file_exists('vendor/'.$sVendor.'/'.$sModule.'/data/structure_simple.sql')) {
?> <br/><input type="radio" name="plc_module_setup_config" value="simple" checked /> Simple
<?php
}
if(file_exists('vendor/'.$sVendor.'/'.$sModule.'/data/structure_extended.sql')) {
?> <br/><input type="radio" name="plc_module_setup_config" value="extended" /> Simple
foreach(glob('vendor/'.$sVendor.'/'.$sModule.'/data/structure_*.sql') as $sConfig) {
$sConfig = str_replace(['.sql'],[],explode('_',basename($sConfig))[1]); ?>
<br/><input type="radio" name="plc_module_setup_config" value="<?=$sConfig?>" checked /> <?=$sConfig?>
<?php
}
}
Expand Down
101 changes: 62 additions & 39 deletions view/one-place/contact/search/index.phtml
Original file line number Diff line number Diff line change
@@ -1,47 +1,70 @@
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h2>Find Contact</h2>
</div>
<?php if(isset($aResults)) { ?>

<?php } else { ?>
<form action="" method="post">
<div class="card-body">
<?= $this->partial('partial/basictabs', ['sFormName'=>$this->sFormName]); ?>
<?= $this->partial('partial/searchtabcontents', ['sFormName'=>$this->sFormName]); ?>
</div>
<div class="card-footer">
<button class="btn btn-primary" type="submit">
Start Search
</button>
</div>
</form>
<?php } ?>
<?php
if(isset($sTableName)) {
$sRoute = (isset($sRoute)) ? $sRoute : explode('-',$sTableName)[0];
?>
<div class="card">
<div class="card-header">
<?= $this->partial('partial/indexheader',['sTitle'=>'Contacts']) ?>
</div>
<div class="card-body py-0">
<?= $this->partial('partial/indextable', [
'sTableName' => $sTableName,
'aItems' => $aItems,
'aFilters' => $aFilters,
'sRoute' => $sRoute
]); ?>
</div>
<div class="card-footer">
<?= $this->partial('partial/indexpager', ['aItems' => $aItems,'sRoute' => $sRoute]); ?>
</div>
</div>
<?php if(isset($aResults)) { ?>
<?php } else { ?>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h2>Results</h2>
</div>
<div class="card-body">
<ul class="list-group">
<?php
foreach($aResults as $oContact) { ?>
<li class="list-group-item">
<a href="<?=$this->url('contact',['action'=>'view','id'=>$oContact->getID()])?>" title="<?=$this->translate('View Contact')?>">
<?=$oContact->getLabel();?>
</a>
</li>
<?php
}
?>
</ul>
<h2>Find Contact</h2>
</div>
<?php if(isset($aResults)) { ?>

<?php } else { ?>
<form action="" method="post">
<div class="card-body">
<?= $this->partial('partial/basictabs', ['sFormName'=>$this->sFormName]); ?>
<?= $this->partial('partial/searchtabcontents', ['sFormName'=>$this->sFormName]); ?>
</div>
<div class="card-footer">
<button class="btn btn-primary" type="submit">
Start Search
</button>
</div>
</form>
<?php } ?>
</div>
</div>
<?php } ?>
</div>
<?php if(isset($aResults)) { ?>
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h2>Results - <?=$aResults->getTotalItemCount()?></h2>
</div>
<div class="card-body">
<ul class="list-group">
<?php
foreach($aResults as $oContact) { ?>
<li class="list-group-item">
<a href="<?=$this->url('contact',['action'=>'view','id'=>$oContact->getID()])?>" title="<?=$this->translate('View Contact')?>">
<?=$oContact->getLabel();?>
</a>
</li>
<?php
}
?>
</ul>
<?= $this->partial('partial/indexpager', ['aItems'=>$aResults,'sRoute'=>'contact-search']); ?>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } ?>

0 comments on commit 0a07894

Please sign in to comment.