From b193f1ee28c5fa11f136bc19373095ca8f6d073d Mon Sep 17 00:00:00 2001 From: Szymon Olewniczak Date: Mon, 8 Jan 2018 11:48:29 +0100 Subject: [PATCH 1/2] "struct_lookup" action for bureaucracy Action allows create struct lookup entries using bureaucracy form. Syntax:
action struct_lookup ...
can contain any number of struct_field or struct_schema. Data will be saved to respective lookup schemas. --- helper/lookup.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++ lang/en/lang.php | 2 ++ 2 files changed, 60 insertions(+) create mode 100644 helper/lookup.php diff --git a/helper/lookup.php b/helper/lookup.php new file mode 100644 index 00000000..35fde9a3 --- /dev/null +++ b/helper/lookup.php @@ -0,0 +1,58 @@ +column->getTable(); + $lbl = $field->column->getLabel(); + if(!isset($tosave[$tbl])) $tosave[$tbl] = array(); + $tosave[$tbl][$lbl] = $field->getParam('value'); + } + + foreach($tosave as $table => $data) { + $access = AccessTable::byTableName($table, 0, 0); + if (!$access instanceof AccessTableLookup) continue; + + if(!$access->getSchema()->isEditable()) { + throw new StructException('lookup save error: no permission for schema'); + } + $validator = $access->getValidator($data); + if($validator->validate()) { + $validator->saveData(); + } + } + + // set thank you message + if(!$thanks) { + $thanks = sprintf($this->getLang('bureaucracy_action_struct_lookup_thanks'), wl($ID)); + } else { + $thanks = hsc($thanks); + } + + return $thanks; + } +} \ No newline at end of file diff --git a/lang/en/lang.php b/lang/en/lang.php index f88bb40b..4ed149fb 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -109,4 +109,6 @@ $lang['lookup new entry'] = 'Create new Entry'; $lang['js']['lookup_delete'] = 'Delete Entry'; +$lang['bureaucracy_action_struct_lookup_thanks'] = 'The entry has been stored. Add another entry.'; + //Setup VIM: ex: et ts=4 : From 6d71ffef4f90b9781358c4719dfc7b6b808519db Mon Sep 17 00:00:00 2001 From: Szymon Olewniczak Date: Tue, 9 Jan 2018 10:41:50 +0100 Subject: [PATCH 2/2] fix: proper error handling --- helper/lookup.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helper/lookup.php b/helper/lookup.php index 35fde9a3..7651bca4 100644 --- a/helper/lookup.php +++ b/helper/lookup.php @@ -38,7 +38,8 @@ public function run($fields, $thanks, $argv) { if (!$access instanceof AccessTableLookup) continue; if(!$access->getSchema()->isEditable()) { - throw new StructException('lookup save error: no permission for schema'); + msg('lookup save error: no permission for schema', -1); + return false; } $validator = $access->getValidator($data); if($validator->validate()) {