Exemplo n.º 1
0
 /**
  * Save the data posted by the inline editor
  */
 protected function inline_save()
 {
     global $INPUT;
     // check preconditions
     if (!$this->initFromInput()) {
         throw new StructException('inline save error: init');
     }
     self::checkCSRF();
     if (!$this->schemadata->getSchema()->isLookup()) {
         $this->checkPage();
     }
     if (!$this->schemadata->getSchema()->isEditable()) {
         throw new StructException('inline save error: no permission for schema');
     }
     // validate
     $value = $INPUT->param('entry');
     $validator = new ValueValidator();
     if (!$validator->validateValue($this->column, $value)) {
         throw new StructException(join("\n", $validator->getErrors()));
     }
     // current data
     $tosave = $this->schemadata->getDataArray();
     $tosave[$this->column->getLabel()] = $value;
     // save
     if ($this->schemadata->getSchema()->isLookup()) {
         $revision = 0;
     } else {
         $revision = helper_plugin_struct::createPageRevision($this->pid, 'inline edit');
     }
     $this->schemadata->setTimestamp($revision);
     try {
         if (!$this->schemadata->saveData($tosave)) {
             throw new StructException('saving failed');
         }
     } finally {
         // unlock (unlocking a non-existing file is okay,
         // so we don't check if it's a lookup here
         unlock($this->pid);
     }
     // reinit then render
     $this->initFromInput();
     $value = $this->schemadata->getDataColumn($this->column);
     $R = new Doku_Renderer_xhtml();
     $value->render($R, 'xhtml');
     // FIXME use configured default renderer
     echo $R->doc;
 }
Exemplo n.º 2
0
 /**
  * Loads all available lookup values
  *
  * @return array
  */
 protected function loadLookupData()
 {
     $schema = $this->schema->getTable();
     $field = $this->column->getLabel();
     $search = new Search();
     $search->addSchema($schema);
     $search->addColumn($field);
     $search->addSort($field);
     $result = $search->execute();
     $pids = $search->getPids();
     $len = count($result);
     /** @var Value[][] $result */
     $options = array('' => '');
     for ($i = 0; $i < $len; $i++) {
         $options[$pids[$i]] = $result[$i][0]->getDisplayValue();
     }
     return $options;
 }