Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions helper/lookup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
use dokuwiki\plugin\struct\meta\AccessTable;
use dokuwiki\plugin\struct\meta\AccessTableLookup;
use dokuwiki\plugin\struct\meta\StructException;

/**
* Allows adding a lookup schema as a bureaucracy action
*
*/
class helper_plugin_struct_lookup extends helper_plugin_bureaucracy_action {

/**
* Performs struct_lookup action
*
* @param helper_plugin_bureaucracy_field[] $fields array with form fields
* @param string $thanks thanks message
* @param array $argv array with entries: template, pagename, separator
* @return array|mixed
*
* @throws Exception
*/
public function run($fields, $thanks, $argv) {
global $ID;

// get all struct values and their associated schemas
$tosave = array();
foreach($fields as $field) {
if(!is_a($field, 'helper_plugin_struct_field')) continue;
/** @var helper_plugin_struct_field $field */
$tbl = $field->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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does throwing a Struct Exception in the bureaucracy context work? I don't think bureaucracy is catching exceptions. Instead a msg() should be shown and false be returned.

}
$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;
}
}
2 changes: 2 additions & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. <a href="%s">Add another entry</a>.';

//Setup VIM: ex: et ts=4 :