/** * Save the user's visible field selections back to the database. We expect * the selections array to just contain field IDs. Only those that match * IDs of fields in the supplied Fields object will be saved. * * @param Fields $fields * @param array $selections * @param boolean $applyToAllUsers * @return void */ public function save(Fields $fields, array $selections, $applyToAllUsers = false) { $visibleFields = []; foreach ($selections as $id) { if ($fields->has($id)) { $visibleFields[] = $id; } } if (count($visibleFields)) { $this->dbAdapter->beginTransaction(); $this->deleteExistingValuesForSave($applyToAllUsers); foreach ($visibleFields as $visibleFieldId) { $data = ['component' => $this->componentName, 'field_id' => $visibleFieldId]; if (!$applyToAllUsers) { foreach ($this->getUserReferenceValues() as $column => $value) { $data[$column] = $value; } } $this->dbAdapter->insert($this->dbTableName, $data); } $this->dbAdapter->commit(); // Reset selections so they'll be loaded again when filter is re-applied $this->selections = null; } }
/** * Save multiple groups of fields to the database. * * @param array $groupConfig * @return void */ protected function saveGroups(array $groupConfig) { $this->dbAdapter->beginTransaction(); $this->deleteCurrentSettings(); foreach ($groupConfig as $index => $group) { $groupId = null; if (self::UNGROUPED !== $index) { $this->dbAdapter->insert('dewdrop_field_groups', array('title' => $group['title'], 'sort_index' => $index)); $groupId = $this->dbAdapter->lastInsertId(); } $this->saveFields($group['fields'], $groupId); } $this->dbAdapter->commit(); }