Skip to content

"struct_lookup" action for bureaucracy #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
59 changes: 59 additions & 0 deletions helper/lookup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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()) {
msg('lookup save error: no permission for schema', -1);
return false;
}
$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 :