From 5db5117cb53a84609a474de836af0c707b0332a0 Mon Sep 17 00:00:00 2001 From: JBinggi Date: Sun, 9 Feb 2020 07:52:02 +0100 Subject: [PATCH] add custom user fields fix bugs --- data/data_simple.sql | 6 +++--- data/structure_simple.sql | 4 ++-- src/Controller/HistoryController.php | 22 +++++++++++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/data/data_simple.sql b/data/data_simple.sql index a6f7566..8085166 100644 --- a/data/data_simple.sql +++ b/data/data_simple.sql @@ -2,8 +2,8 @@ -- add type fields -- 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, 'select', 'Type', 'supplier_idfs', 'history-base', 'articlehistory-single', 'col-md-2', '', '/contact/api/list/0', 0, 1, 0, 'entitytag-single', 'OnePlace\\Contact\\Model\\ContactTable','add-OnePlace\\Contact\\Controller\\ContactController'), -(NULL, 'datetime', 'Date', 'date', 'history-base', 'articlehistory-single', 'col-md-2', '', '', 0, 1, 0, '', '', ''), -(NULL, 'currency', 'Price', 'price', 'history-base', 'articlehistory-single', 'col-md-2', '', '', 0, 1, 0, '', '', ''), +(NULL, 'select', 'Supplier', 'supplier_idfs', 'history-base', 'articlehistory-single', 'col-md-3', '', '/contact/api/list/0', 0, 1, 0, 'entitytag-single', 'OnePlace\\Contact\\Model\\ContactTable','add-OnePlace\\Contact\\Controller\\ContactController'), +(NULL, 'datetime', 'Date', 'date', 'history-base', 'articlehistory-single', 'col-md-1', '', '', 0, 1, 0, '', '', ''), +(NULL, 'currency', 'Price', 'price', 'history-base', 'articlehistory-single', 'col-md-1', '', '', 0, 1, 0, '', '', ''), (NULL, 'number', 'Amount', 'amount', 'history-base', 'articlehistory-single', 'col-md-1', '', '', 0, 1, 0, '', '', ''); diff --git a/data/structure_simple.sql b/data/structure_simple.sql index 188d9ad..8a6141d 100644 --- a/data/structure_simple.sql +++ b/data/structure_simple.sql @@ -1,5 +1,5 @@ ALTER TABLE `article_history` ADD `supplier_idfs` INT(11) NOT NULL DEFAULT '0' AFTER `article_idfs`, -ADD `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `supplier_idfs`; -ADD `price` FLOAT NOT NULL DEFAULT 0 AFTER `date`; +ADD `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `supplier_idfs`, +ADD `price` FLOAT NOT NULL DEFAULT 0 AFTER `date`, ADD `amount` FLOAT NOT NULL DEFAULT 0 AFTER `price`; diff --git a/src/Controller/HistoryController.php b/src/Controller/HistoryController.php index 8d2bf51..dc64e47 100644 --- a/src/Controller/HistoryController.php +++ b/src/Controller/HistoryController.php @@ -53,15 +53,27 @@ public function __construct(AdapterInterface $oDbAdapter,HistoryTable $oTableGat public function attachHistoryForm($oItem = false) { $oForm = CoreEntityController::$aCoreTables['core-form']->select(['form_key'=>'articlehistory-single']); - $aFields = [ - 'history-base' => CoreEntityController::$aCoreTables['core-form-field']->select(['form' => 'articlehistory-single']), - ]; + $aFields = []; + $aUserFields = CoreEntityController::$oSession->oUser->getMyFormFields(); + if(array_key_exists('articlehistory-single',$aUserFields)) { + $aFieldsTmp = $aUserFields['articlehistory-single']; + if(count($aFieldsTmp) > 0) { + # add all contact-base fields + foreach($aFieldsTmp as $oField) { + if($oField->tab == 'history-base') { + $aFields[] = $oField; + } + } + } + } + + $aFieldsByTab = ['history-base'=>$aFields]; # Try to get adress table try { $oHistoryTbl = CoreEntityController::$oServiceManager->get(HistoryTable::class); } catch(\RuntimeException $e) { - //echo '
Error: Could not load address table
'; + echo '
Error: Could not load address table
'; return []; } @@ -90,7 +102,7 @@ public function attachHistoryForm($oItem = false) { 'article_history'=> [ 'oHistories'=>$aHistories, 'oForm'=>$oForm, - 'aFormFields'=>$aFields, + 'aFormFields'=>$aFieldsByTab, ] ] ];