_db->select(); $select->from($this->_getSubPair('Category', 'sc'), array('id', 'name'))->order('sc.sorter'); return $this->_db->fetchPairs($select); } public function insertSettingOptions() { $data = $this->getData(); foreach ($data['settingOptions'] as $option) { if (!empty($option['variable'])) { $option['name'] = $data['name']; $this->_getTable('SettingsOptions')->insert($option); } } return $this; } public function initFromForm(array $data) { parent::initFromForm($data); $this->_data['name'] = $this->_data['newName']; unset($this->_data['newName']); return $this; } protected function _insertDependency() { $this->insertSettingOptions(); return $this; } protected function _updateDependency() { $this->deleteSettingOptions(); $this->insertSettingOptions(); return parent::_updateDependency(); } protected function _addDependenciesFromDb(array &$data) { $data['settingOptions'] = $this->_getFieldOptionByFieldName($data['name']); return $this; } protected function _getFieldOptionByFieldName($name) { $select = $this->_db->select(); $select->from($this->_getPair($this->_tableAlias . 'Options')); $select->where('name = ?', $name); $select->order('sorter'); return $this->_db->fetchAll($select); } public function deleteSettingOptions() { $this->_getTable('SettingsOptions')->deleteBy(array('name' => $this->getPrimaryKey())); return $this; } public function getListSelect() { if (null == $this->_select) { $this->_select = parent::getListSelect(); $this->_select->joinLeft( $this->_getPair('SettingsCategory'), '`SettingsCategory`.`id` = `Settings`.`idCategory`', array('category' => 'SettingsCategory.name') ); } return $this->_select; } }