public function test_autocomplete()
 {
     global $INPUT;
     $schema = new Schema('tag');
     // search tag field, should not find Aragon because tag is not in current revision
     $INPUT->set('search', 'ar');
     $tag = $schema->findColumn('tag')->getType();
     $return = $tag->handleAjax();
     $expect = array(array('label' => 'Eldarion', 'value' => 'Eldarion'), array('label' => 'Treebeard', 'value' => 'Treebeard'));
     $this->assertEquals($expect, $return);
     // multi value
     $INPUT->set('search', 'ar');
     $tag = $schema->findColumn('tags')->getType();
     $return = $tag->handleAjax();
     $expect = array(array('label' => 'Arwen', 'value' => 'Arwen'), array('label' => 'Saruman', 'value' => 'Saruman'));
     $this->assertEquals($expect, $return);
 }
Exemplo n.º 2
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.º 3
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();
 }
Exemplo n.º 4
0
 /**
  * Tries to find the correct column and schema
  *
  * @throws StructException
  * @param string $colname
  * @return \dokuwiki\plugin\struct\meta\Column
  */
 protected function findColumn($colname)
 {
     list($table, $label) = explode('.', $colname, 2);
     if (!$table || !$label) {
         throw new StructException('Field \'%s\' not given in schema.field form', $colname);
     }
     $schema = new Schema($table);
     return $schema->findColumn($label);
 }