/**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * Get the json of the current version of the given schema or false if the schema doesn't exist.
  *
  * @param string $schemaName
  * @return string|bool The json string or false if the schema doesn't exist
  */
 public function getCurrentSchemaJSON($schemaName)
 {
     $schema = new Schema($schemaName);
     if ($schema->getId() == 0) {
         return false;
     }
     return $schema->toJSON();
 }
 public function test_deleteok()
 {
     $this->loadSchemaJSON('schema1');
     $schema = new Schema('schema1');
     $this->assertEquals(1, $schema->getId());
     $schema->delete();
     $this->assertEquals(0, $schema->getId());
     $schema = new Schema('schema1');
     $this->assertEquals(0, $schema->getId());
 }
Exemplo n.º 4
0
 /**
  * Dropdown constructor.
  *
  * @param array|null $config
  * @param string $label
  * @param bool $ismulti
  * @param int $tid
  */
 public function __construct($config = null, $label = '', $ismulti = false, $tid = 0)
 {
     global $conf;
     parent::__construct($config, $label, $ismulti, $tid);
     $this->config['schema'] = Schema::cleanTableName($this->config['schema']);
     if ($this->usesLookup()) {
         $this->schema = new Schema($this->config['schema']);
         if (!$this->schema->getId()) {
             // schema does not exist
             msg(sprintf('Schema %s does not exist', $this->config['schema']), -1);
             $this->schema = null;
             $this->config['schema'] = '';
             return;
         }
         // apply language replacement
         $field = str_replace('$LANG', $conf['lang'], $this->config['field']);
         $this->column = $this->schema->findColumn($field);
         if (!$this->column) {
             $field = str_replace('$LANG', 'en', $this->config['field']);
             // fallback to en
             $this->column = $this->schema->findColumn($field);
         }
         if (!$this->column) {
             // field does not exist
             msg(sprintf('Field %s.%s does not exist', $this->config['schema'], $this->config['field']), -1);
             $this->column = null;
             $this->config['field'] = '';
             return;
         }
         if ($this->column->isMulti()) {
             // field is multi
             msg(sprintf('Field %s.%s is a multi field - not allowed for lookup', $this->config['schema'], $this->config['field']), -1);
             $this->column = null;
             $this->config['field'] = '';
             return;
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Add a schema to be searched
  *
  * Call multiple times for multiple schemas.
  *
  * @param string $table
  * @param string $alias
  */
 public function addSchema($table, $alias = '')
 {
     $schema = new Schema($table);
     if (!$schema->getId()) {
         throw new StructException('schema missing', $table);
     }
     if ($this->schemas && ($schema->isLookup() || reset($this->schemas)->isLookup())) {
         throw new StructException('nolookupmix');
     }
     $this->schemas[$table] = $schema;
     if ($alias) {
         $this->aliases[$alias] = $table;
     }
 }
Exemplo n.º 6
0
 /**
  * Check the input variables and run the AJAX call
  *
  * @throws StructException
  * @return mixed
  */
 protected function executeTypeAjax()
 {
     global $INPUT;
     $col = $INPUT->str('column');
     if (blank($col)) {
         throw new StructException('No column provided');
     }
     list($schema, $colname) = explode('.', $col, 2);
     if (blank($schema) || blank($colname)) {
         throw new StructException('Column format is wrong');
     }
     $schema = new Schema($schema);
     if (!$schema->getId()) {
         throw new StructException('Unknown Schema');
     }
     $column = $schema->findColumn($colname);
     if ($column === false) {
         throw new StructException('Column not found');
     }
     return $column->getType()->handleAjax();
 }