public function add() { $isSent = Request::get(1, VAR_URI) == 'send'; $this->breadcrumb->add('Hinzufügen'); $this->header(); $_positions = $this->getPositions(); $positions = Core::constructObjectArray($_positions); $_fieldTypes = $this->getFieldTypes(); $fieldTypes = Core::constructObjectArray($_fieldTypes); $data = array('name' => '', 'description' => '', 'internal' => '', 'priority' => 0, 'position' => reset($_positions), 'type' => reset($_fieldTypes), 'read' => array(), 'write' => array()); foreach (CustomField::getRights() as $right) { foreach (array('read', 'write') as $type) { $data[$type][$right] = 1; } } $error = array(); if ($isSent) { // Base options for every field $options = array_merge($this->getValidator(), array('internal' => array(Validator::OPTIONAL => true, Validator::MULTIPLE => array(array(Validator::MESSAGE => 'Der interne Name enthält Zeichen die nicht erlaubt sind. Erlaubt sind: a-z, 0-9, _, -', Validator::REGEXP => Validator::RE_URI, Validator::OPTIONAL => true), array(Validator::MESSAGE => 'Der interne Name darf maximal 32 Zeichen lang sein.', Validator::MAX_LENGTH => 32), array(Validator::MESSAGE => 'Der interne Name existiert bereits für eine anderes Feld der Tabelle.', Validator::CLOSURE => function ($internal) use(&$_positions) { if (!empty($internal)) { $db = Database::getObject(); $db->query("SELECT id FROM <p>fields WHERE internal = <internal> AND position IN(<_positions:string[]>)", compact("internal", "_positions")); return $db->numRows() == 0; } return true; // If nothing is specified we will generate a valid name }))), 'position' => array(Validator::MESSAGE => 'Der Anzeigeort ist ungültig.', Validator::LIST_CS => $_positions), 'type' => array(Validator::MESSAGE => 'Der Feldtyp ist ungültig.', Validator::LIST_CS => $_fieldTypes))); // get additional options for the specified field $type = Request::get('type'); if (isset($fieldTypes[$type])) { $options = array_merge($options, $fieldTypes[$type]->getValidationParams(true)); } extract(Validator::checkRequest($options)); if (count($error) == 0) { $field = $fieldTypes[$data['type']]; $this->injectDataToField($field, $data); if ($field->create()) { CmsPage::ok("Das Feld wurde erfolgreich angelegt."); } else { $error[] = 'Das Feld konnt leider nicht angelegt werden.'; } } if (count($error) > 0) { CmsPage::error($error); } } if (!$isSent || count($error) > 0) { $tpl = Response::getObject()->appendTemplate("/Cms/admin/fields_add"); $tpl->assign('positions', $positions, false); $tpl->assign('types', $fieldTypes, false); $tpl->assign('data', $data, false); $tpl->assign('baseUri', $this->getBaseURI()); $tpl->output(); } $this->footer(); }
public static function ensurePermissionsValid($permissions) { $data = array(); foreach (CustomField::getRights() as $right) { foreach (array('read', 'write') as $type) { if (empty($permissions[$type][$right])) { $data[$type][$right] = 0; } else { $data[$type][$right] = 1; } } } return $data; }