_data['password'])) { unset($this->_data['password']); } else { $this->_data['salt'] = substr(md5(time()), 0, 8); $this->_data['password'] = $this->_encryptPass($this->_data['password'], $this->_data['salt']); } if (isset($this->_data['joinDate']) && empty($this->_data['joinDate'])) { $this->_data['joinDate'] = new \Zend_Db_Expr('NULL'); } if (isset($this->_data['state']) && empty($this->_data['state'])) { $this->_data['state'] = new \Zend_Db_Expr('NULL'); } if ('n' == $this->_data['active']) { unset($this->_data['memberId']); } return $this; } public function getAddressTypes() { if (null === $this->_addressTypes) { $tableData = $this->_getTable($this->_tableAlias . 'Address')->getMetaData(); $types = $tableData['type']['DATA_TYPE']; if (false === stripos($types, 'set(')) { throw new Qs_Db_Obj_Exception('Unknown type of address type column'); } $types = substr($types, 4, -1); $types = explode(',', $types); array_walk($types, function (&$item, $key) { $item = trim($item, "' "); }); if (empty($types)) { throw new Qs_Db_Obj_Exception('Wrong format of address type column'); } $types = array_filter($types); $types = array_merge($types); if (!in_array(static::ADDRESS_BILLING, $types)) { throw new Qs_Db_Obj_Exception('"billing" type is required for address type column'); } $billingIndex = array_search(static::ADDRESS_BILLING, $types); if (0 !== $billingIndex) { unset($types[$billingIndex]); array_unshift($types, static::ADDRESS_BILLING); } $this->_addressTypes = $types; } return $this->_addressTypes; } public function getObjectInfo() { $data = (array) $this->getData(); if (!empty($data)) { $data['itemTitle'] = $data['firstName'] . ' ' . $data['lastName']; } return $data; } protected function _getFromColumns() { $columns = parent::_getFromColumns(); $columns['name'] = self::getNameField(); $columns['leadership'] = new Zend_Db_Expr('(' . $this->_getLeadershipSubselect() . ')'); $columns['jobAmount'] = new Zend_Db_Expr('(' . $this->_getJobAmountSubselect() . ')'); return $columns; } protected function _getJobAmountSubselect() { $select = $this->_db->select(); $select->from($this->_getPair('Job'), 'COUNT(*)'); $select->where('`' . $this->_tableAlias . '`.`id` = `Job`.`userId`'); return $select; } protected function _getLeadershipSubselect() { $select = $this->_db->select(); $select->from($this->_getPair($this->_tableAlias . 'Group'), 'title'); $select->where('`' . $this->_tableAlias . '`.`groupId` = `' . $this->_tableAlias . 'Group`.`id`'); $select->limit(1); return $select; } static public function getNameField() { return new Zend_Db_Expr('IF (`suffix` != "", CONCAT_WS(", ", CONCAT_WS(" ", `firstName`, `middleInitial`, `lastName`), `suffix`), CONCAT_WS(" ", `firstName`, `middleInitial`, `lastName`))'); } public function getListStatement() { $this->_filterByGroup(); return parent::getListStatement(); } protected function _filterByGroup() { if (!empty($this->_filter['leadership'])) { $this->addFilter(array('groupId' => $this->_filter['leadership'])); } return $this; } public static function getAutocompleteColumns() { return array( 'value' => 'id', 'title' => App_User_Abstract_Obj::getNameField() ); } protected static function _getAutocompleteItemSelect($userId) { $columns = self::getAutocompleteColumns(); unset($columns['value']); $select = \Qs_Db::getSelect(); $select->from(\Qs_Db::getPair('User'), $columns); $select->where('id = ?', $userId, \Qs_Db::INT_TYPE); $select->limit(1); return $select; } public function getAutocompleteNameEmail($term) { $select = $this->_db->select(); $select->from($this->_getPair('User'), self::getAutocompleteColumns()) ->where('`active` = "y"') ->where('`firstName` LIKE ? OR `lastName` LIKE ? OR `email` LIKE ?', '%' . $term . '%'); return $this->_db->fetchAll($select); } public static function getAutocompleteItemTitle($userId) { $select = static::_getAutocompleteItemSelect($userId); return \Qs_Db::getInstance()->fetchOne($select); } }