schema = $schema; $this->hlp = plugin_load('helper', 'struct_config'); } /** * Returns the Admin Form to edit the schema * * This data is processed by the SchemaBuilder class * * @return string the HTML for the editor form * @see SchemaBuilder */ public function getEditor() { $form = new Form(array('method' => 'POST', 'id'=>'plugin__struct_editor')); $form->setHiddenField('do', 'admin'); $form->setHiddenField('page', 'struct_schemas'); $form->setHiddenField('table', $this->schema->getTable()); $form->setHiddenField('schema[id]', $this->schema->getId()); $form->setHiddenField('schema[islookup]', $this->schema->isLookup()); $form->addHTML(''); $form->addHTML(""); foreach($this->schema->getColumns() as $key => $col) { $form->addHTML($this->adminColumn($col->getColref(), $col)); } // FIXME new one needs to be added dynamically, this is just for testing $form->addHTML($this->adminColumn('new1', new Column($this->schema->getMaxsort()+10, new Text()), 'new')); $form->addHTML('
{$this->hlp->getLang('editor_sort')} {$this->hlp->getLang('editor_label')} {$this->hlp->getLang('editor_multi')} {$this->hlp->getLang('editor_conf')} {$this->hlp->getLang('editor_type')} {$this->hlp->getLang('editor_enabled')}
'); $form->addButton('save', 'Save')->attr('type','submit'); return $form->toHTML() . $this->initJSONEditor(); } /** * Gives the code to attach the JSON editor to the config field * * We do not use the "normal" way, because this is rarely used code and there's no need to always load it. * @return string */ protected function initJSONEditor() { $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; return $html; } /** * Returns the HTML to edit a single column definition of the schema * * @param string $column_id * @param Column $col * @param string $key The key to use in the form * @return string * @todo this should probably be reused for adding new columns via AJAX later? */ protected function adminColumn($column_id, Column $col, $key='cols') { $base = 'schema['.$key.'][' . $column_id . ']'; // base name for all fields $class = $col->isEnabled() ? '' : 'disabled'; $html = ""; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $checked = $col->getType()->isMulti() ? 'checked="checked"' : ''; $html .= ''; $html .= ''; $html .= ''; $config = json_encode($col->getType()->getConfig(), JSON_PRETTY_PRINT); $html .= ''; $html .= ''; $types = Column::allTypes(); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $checked = $col->isEnabled() ? 'checked="checked"' : ''; $html .= ''; $html .= ''; $html .= ''; return $html; } }