_filterFields, self::getNameField()); $this->_reorderTitleColumn = 'name'; parent::_init(); } public function getUser4Json($term) { $select = $this->_db->select(); $select->from($this->_getPair(), array('value' => 'id', 'label' => 'CONCAT(`firstName`, " ", `lastName`)')) ->where('`firstName` LIKE ? OR `lastName` LIKE ?', '%' . $term . '%') ->where('`active` = "y"'); return $this->_db->fetchAll($select); } public function changeEnumOption($name) { if ('active' === $name) { $memberId = $this->getData('memberId'); if ('n' == $this->getData('active') && empty($memberId)) { $this->_addError(static::MSG_INVALID_MEMBER_ID); return false; } } return parent::changeEnumOption($name); } protected function _deleteDependency() { $this->_deleteIds('Job', 'userId'); return parent::_deleteDependency(); } protected function _isActiveUser() { $select = $this->_db->select(); $select->from($this->_getTableName(), 'active'); $select->where('`id` = ?', $this->getPrimaryKey()); $select->limit(1); return 'y' == $this->_db->fetchOne($select); } protected function _getCurrentSorter() { $select = $this->_db->select(); $select->from($this->_getTableName(), array(self::SORTER_LEADERSHIP)); $select->where('`id` = ?', $this->getPrimaryKey()); $select->limit(1); return $this->_db->fetchRow($select); } protected function _getMaxSorter($fieldSorter) { $this->setSorterField($fieldSorter); $select = $this->_db->select(); $select->from($this->_getPair(), "MAX(`{$fieldSorter}`)"); $this->_where4Sorter($select); $select->limit(1); return (null === ($sorter = $this->_db->fetchOne($select))) ? 0 : $sorter + 1; } public function insert(array $data = null) { if (null === $data) { $data = $this->_data; } else { $this->_data = $data; } $this->_initSorter($data, true); return parent::insert($data); } public function update(array $data = null) { if (null === $data) { $data = $this->_data; } else { $this->_data = $data; } $newActive = 'y' == $data['active']; $active = $this->_isActiveUser(); $this->_initSorter($data); $result = parent::update($data); return $result; } protected function _initSorter(array &$data, $newMember = false) { if ($newMember) { $currentSorter = array(); } else { $currentSorter = $this->_getCurrentSorter(); } if (empty($data['groupId'])) { $data[self::SORTER_LEADERSHIP] = null; } else if (!isset($currentSorter[self::SORTER_LEADERSHIP])) { $data[self::SORTER_LEADERSHIP] = $this->_getMaxSorter(self::SORTER_LEADERSHIP); } return $this; } public function setSorterField($sorter) { $this->_sorterField = $sorter; return $this; } public function getSorterField() { if (null === $this->_sorterField) { $this->_sorterField = self::SORTER_LEADERSHIP; } return $this->_sorterField; } protected function _getReorderSelect() { $select = clone $this->getListSelect(); $this->_where4Sorter($select); $select->order($this->_tableAlias . '.' . $this->getSorterField()); return $select; } protected function _where4Sorter(Zend_Db_Select $select) { if (self::SORTER_LEADERSHIP == $this->getSorterField() && !array_key_exists('groupId', $this->_filter)) { $select->where('groupId = ?', (int) $this->getData('groupId')); } return parent::_where4Sorter($select); } public function updateOrder(array $order) { if ($this->getSorterField() == self::SORTER_LEADERSHIP) { foreach ($order as $sorter => $id) { $this->_getTable()->updateByKey(array($this->getSorterField() => (int)$sorter), $id); } } return $this; } protected function _filter(Zend_Db_Select $select) { parent::_filter($select); if (!empty($this->_filter['committeeId'])) { $select->join($this->_getPair('UserCommittee', 'uc'), '`uc`.`userId` = `User`.`id`', array()); $select->where('`uc`.`committeeId` = ?', $this->_filter['committeeId'], \Qs_Db::INT_TYPE); } return $this; } }