/**
  * Load a whole schema as fields
  *
  * @param Doku_Event $event event object by reference
  * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
  *                           handler was registered]
  * @return bool
  */
 public function handle_schema(Doku_Event $event, $param)
 {
     $args = $event->data['args'];
     if ($args[0] != 'struct_schema') {
         return false;
     }
     $event->preventDefault();
     $event->stopPropagation();
     /** @var helper_plugin_bureaucracy_field $helper */
     $helper = plugin_load('helper', 'bureaucracy_field');
     $helper->initialize($args);
     $schema = new Schema($helper->opt['label']);
     if (!$schema->getId()) {
         msg('This schema does not exist', -1);
         return false;
     }
     foreach ($schema->getColumns(false) as $column) {
         /** @var helper_plugin_struct_field $field */
         $field = plugin_load('helper', 'struct_field');
         // we don't initialize the field but set the appropriate values
         $field->opt = $helper->opt;
         // copy all the settings to each field
         $field->opt['label'] = $column->getFullQualifiedLabel();
         $field->column = $column;
         $event->data['fields'][] = $field;
     }
     return true;
 }
 public function test_import_one()
 {
     $sb = new meta\SchemaImporter('tag', file_get_contents(__DIR__ . '/json/tag.struct.json'));
     $this->assertTrue((bool) $sb->build());
     $schema = new meta\Schema('tag');
     $columns = $schema->getColumns();
     $this->assertEquals(2, count($columns));
     $this->assertTrue(is_a($columns[0], '\\dokuwiki\\plugin\\struct\\meta\\Column'));
     $this->assertTrue(is_a($columns[1], '\\dokuwiki\\plugin\\struct\\meta\\Column'));
     $this->assertEquals('tag', $columns[0]->getLabel());
     $this->assertEquals('tags', $columns[1]->getLabel());
 }
Exemplo n.º 3
0
 /**
  * Create the Editor for a new lookup row
  */
 protected function lookup_new()
 {
     global $INPUT;
     global $lang;
     $tablename = $INPUT->str('schema');
     $schema = new Schema($tablename);
     if (!$schema->isEditable()) {
         return;
     }
     // no permissions, no editor
     echo '<div class="struct_entry_form">';
     echo '<fieldset>';
     echo '<legend>' . $this->getLang('lookup new entry') . '</legend>';
     /** @var action_plugin_struct_entry $entry */
     $entry = plugin_load('action', 'struct_entry');
     foreach ($schema->getColumns(false) as $column) {
         $label = $column->getLabel();
         $field = new Value($column, '');
         echo $entry->makeField($field, "entry[{$label}]");
     }
     formSecurityToken();
     // csrf protection
     echo '<input type="hidden" name="call" value="plugin_struct_lookup_save" />';
     echo '<input type="hidden" name="schema" value="' . hsc($tablename) . '" />';
     echo '<button type="submit">' . $lang['btn_save'] . '</button>';
     echo '<div class="err"></div>';
     echo '</fieldset>';
     echo '</div>';
 }