Skip to content

Commit f38cc29

Browse files
authored
Merge pull request #368 from solewniczak/feature-bureaucracy-action-lookup
"struct_lookup" action for bureaucracy
2 parents d6e3612 + 6d71ffe commit f38cc29

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

helper/lookup.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
use dokuwiki\plugin\struct\meta\AccessTable;
3+
use dokuwiki\plugin\struct\meta\AccessTableLookup;
4+
use dokuwiki\plugin\struct\meta\StructException;
5+
6+
/**
7+
* Allows adding a lookup schema as a bureaucracy action
8+
*
9+
*/
10+
class helper_plugin_struct_lookup extends helper_plugin_bureaucracy_action {
11+
12+
/**
13+
* Performs struct_lookup action
14+
*
15+
* @param helper_plugin_bureaucracy_field[] $fields array with form fields
16+
* @param string $thanks thanks message
17+
* @param array $argv array with entries: template, pagename, separator
18+
* @return array|mixed
19+
*
20+
* @throws Exception
21+
*/
22+
public function run($fields, $thanks, $argv) {
23+
global $ID;
24+
25+
// get all struct values and their associated schemas
26+
$tosave = array();
27+
foreach($fields as $field) {
28+
if(!is_a($field, 'helper_plugin_struct_field')) continue;
29+
/** @var helper_plugin_struct_field $field */
30+
$tbl = $field->column->getTable();
31+
$lbl = $field->column->getLabel();
32+
if(!isset($tosave[$tbl])) $tosave[$tbl] = array();
33+
$tosave[$tbl][$lbl] = $field->getParam('value');
34+
}
35+
36+
foreach($tosave as $table => $data) {
37+
$access = AccessTable::byTableName($table, 0, 0);
38+
if (!$access instanceof AccessTableLookup) continue;
39+
40+
if(!$access->getSchema()->isEditable()) {
41+
msg('lookup save error: no permission for schema', -1);
42+
return false;
43+
}
44+
$validator = $access->getValidator($data);
45+
if($validator->validate()) {
46+
$validator->saveData();
47+
}
48+
}
49+
50+
// set thank you message
51+
if(!$thanks) {
52+
$thanks = sprintf($this->getLang('bureaucracy_action_struct_lookup_thanks'), wl($ID));
53+
} else {
54+
$thanks = hsc($thanks);
55+
}
56+
57+
return $thanks;
58+
}
59+
}

lang/en/lang.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,6 @@
109109
$lang['lookup new entry'] = 'Create new Entry';
110110
$lang['js']['lookup_delete'] = 'Delete Entry';
111111

112+
$lang['bureaucracy_action_struct_lookup_thanks'] = 'The entry has been stored. <a href="%s">Add another entry</a>.';
113+
112114
//Setup VIM: ex: et ts=4 :

0 commit comments

Comments
 (0)