/** @noinspection PhpMissingParentConstructorInspection * @param int $sort * @param Decimal $type * @param string $table */ public function __construct($sort, Decimal $type, $table) { if ($type->isMulti()) { throw new StructException('RowColumns can not be multi value types!'); } Column::__construct($sort, $type, 0, true, $table); }
/** * PageColumn constructor. * * @param int $sort * @param Page $type * @param string $table */ public function __construct($sort, Page $type, $table = '') { if ($type->isMulti()) { throw new StructException('PageColumns can not be multi value types!'); } parent::__construct($sort, $type, 0, true, $table); }
/** * Initialize internal state based on input variables * * @return bool if initialization was successfull */ protected function initFromInput() { global $INPUT; $this->schemadata = null; $this->column = null; $pid = $INPUT->str('pid'); list($table, $field) = explode('.', $INPUT->str('field')); if (blank($pid)) { return false; } if (blank($table)) { return false; } if (blank($field)) { return false; } $this->pid = $pid; try { $this->schemadata = AccessTable::byTableName($table, $pid); } catch (StructException $ignore) { return false; } $this->column = $this->schemadata->getSchema()->findColumn($field); if (!$this->column || !$this->column->isVisibleInEditor()) { $this->schemadata = null; $this->column = null; return false; } return true; }
/** * Validate a single value * * @param Column $col the column of that value * @param mixed &$rawvalue the value, will be fixed according to the type * @return bool */ public function validateValue(Column $col, &$rawvalue) { // fix multi value types $type = $col->getType(); $trans = $type->getTranslatedLabel(); if ($type->isMulti() && !is_array($rawvalue)) { $rawvalue = $type->splitValues($rawvalue); } // strip empty fields from multi vals if (is_array($rawvalue)) { $rawvalue = array_filter($rawvalue, array($this, 'filter')); $rawvalue = array_values($rawvalue); // reset the array keys } // validate data return $this->validateField($type, $trans, $rawvalue); }
/** * Sort by lookup table * * @param QueryBuilder $QB * @param string $tablealias * @param string $colname * @param string $order */ public function sort(QueryBuilder $QB, $tablealias, $colname, $order) { if (!$this->usesLookup()) { parent::sort($QB, $tablealias, $colname, $order); return; } $schema = 'data_' . $this->schema->getTable(); $field = $this->column->getColName(); $rightalias = $QB->generateTableAlias(); $QB->addLeftJoin($tablealias, $schema, $rightalias, "{$tablealias}.{$colname} = {$rightalias}.pid"); $this->column->getType()->sort($QB, $rightalias, $field, $order); }
/** * 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 = "<tr class=\"{$class}\">"; $html .= '<td class="sort">'; $html .= '<input type="text" name="' . $base . '[sort]" value="' . hsc($col->getSort()) . '" size="3">'; $html .= '</td>'; $html .= '<td class="label">'; $html .= '<input type="text" name="' . $base . '[label]" value="' . hsc($col->getType()->getLabel()) . '">'; $html .= '</td>'; $html .= '<td class="ismulti">'; $checked = $col->getType()->isMulti() ? 'checked="checked"' : ''; $html .= '<input type="checkbox" name="' . $base . '[ismulti]" value="1" ' . $checked . '>'; $html .= '</td>'; $html .= '<td class="config">'; $config = json_encode($col->getType()->getConfig(), JSON_PRETTY_PRINT); $html .= '<textarea name="' . $base . '[config]" cols="45" rows="10" class="config">' . hsc($config) . '</textarea>'; $html .= '</td>'; $types = Column::allTypes(); $html .= '<td class="class">'; $html .= '<select name="' . $base . '[class]">'; foreach ($types as $type) { $selected = $col->getType()->getClass() == $type ? 'selected="selected"' : ''; $html .= '<option value="' . hsc($type) . '" ' . $selected . '>' . hsc($type) . '</option>'; } $html .= '</select>'; $html .= '</td>'; $html .= '<td class="isenabled">'; $checked = $col->isEnabled() ? 'checked="checked"' : ''; $html .= '<input type="checkbox" name="' . $base . '[isenabled]" value="1" ' . $checked . '>'; $html .= '</td>'; $html .= '</tr>'; return $html; }