public function saveFieldLinks(array $data) { $metaField = DataCenterDBMetaField::newFromValues($data['row']); $metaFieldLinks = $metaField->getLinks(); // Build table of links that do exist $doesExistTable = array(); foreach ($metaFieldLinks as $metaFieldLink) { $key = implode('_', $metaFieldLink->get(array('component_category', 'component_type'))); $doesExistTable[$key] = $metaFieldLink; } // Build table of links that should exist $shouldExistTable = array(); foreach ($data['meta'] as $key => $value) { list($category, $type) = explode('_', $key); $shouldExistTable[$category . '_' . $type] = true; } // Solve the difference foreach (self::$targets as $category => $types) { foreach ($types as $type) { $key = $category . '_' . $type; if (isset($shouldExistTable[$key]) && !isset($doesExistTable[$key])) { // Insert new $metaFieldLink = DataCenterDBMetaFieldLink::newFromValues(array('field' => $metaField->getId(), 'component_category' => $category, 'component_type' => $type)); $metaFieldLink->insert(); } elseif (!isset($shouldExistTable[$key]) && isset($doesExistTable[$key]) && $doesExistTable[$key]->numValues() == 0) { // Remove existing $doesExistTable[$key]->delete(); } } } }
public function configure($path) { // Detects mode if (!$path['id']) { // Creates new component $field = DataCenterDBMetaField::newFromValues(); // Sets 'do' specific parameters $formParameters = array('label' => 'add', 'success' => array('page' => 'settings', 'type' => 'field')); $rows = array(DataCenterUI::renderWidget('heading', array('message' => 'adding-type', 'type' => 'field'))); } else { // Gets component from database $field = DataCenterDB::getMetaField($path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'settings', 'type' => 'field', 'action' => 'view', 'id' => $path['id'])); $rows = array(DataCenterUI::renderWidget('heading', array('message' => 'configuring-type', 'type' => 'field')), DataCenterUI::renderWidget('body', array('message' => 'important-configuring-field', 'style' => 'important'))); } // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array_merge($rows, array(DataCenterUI::renderWidget('form', array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'settings', 'type' => 'field'), 'row' => $field, 'fields' => array('name' => array('type' => 'string'), 'format' => array('type' => 'list', 'enum' => array('category' => 'meta', 'type' => 'field', 'field' => 'format'))))))))), ' ')); }
public function remove(array $data, $type) { if (!DataCenterPage::userCan('remove')) { return false; } // Checks for confirmation if (!isset($data['row']['confirm']) || $data['row']['confirm'] != 'yes') { return false; } switch ($type) { case 'field': $field = DataCenterDBMetaField::newFromValues($data['row']); $values = $field->getValues(); foreach ($values as $value) { $value->delete(); } $field->delete(); return true; } return false; }