_getTable()->getMetaData(); } public function initFromForm(array $data) { Model::prepareFormData($data); return parent::initFromForm($data); } public function insert(array $data = null) { if (null !== $data) { Model::prepareFormData($data); } return parent::insert($data); } public function update(array $data = null) { if (null !== $data) { Model::prepareFormData($data); } $this->_initPreviousData(); return parent::update($data); } protected function _initPreviousData() { $this->_previousData = $this->_getFromDb($this->getPrimaryKey()); return $this; } public function getListSelect() { if (null === $this->_select) { parent::getListSelect(); $this->_joinStatutoryAuthority($this->_select); } return $this->_select; } protected function _joinStatutoryAuthority(Zend_Db_Select $select) { $select->joinLeft( $this->_getPair('StatutoryAuthority', 'sa'), '`sa`.`id` = ' . $this->_quoteField('statutoryAuthorityId'), ['statutoryAuthorityTitle' => 'title'] ); return $this; } protected function _getFromColumns() { $columns = parent::_getFromColumns(); $columns['houseDistrict'] = Model::getMnHouseDistrictColumn(); $columns['congressDistrict'] = Model::getUsCongressDistrictColumn(); return $columns; } protected function _addDependenciesFromDb(array &$data) { $address = Model::createAddress($data); $mailingAddress = Model::createAddress($data, 'mailing'); if (array_values($address) == array_values($mailingAddress)) { $data['asPhysicalAddress'] = 'y'; } $data['utilityCategoryId'] = $this->_getUtilityCategoriesFromDb(); $data['associateCategory'] = $this->_getAssociateCategoriesFromDb(); $data['safetyGroupId'] = $this->_getSafetyGroupsFromDb(); $data['district'] = $this->_getDistrictsFromDb(); $data['permission'] = $this->_getPermissionsFromDb(); $data['position'] = $this->_getPositionsFromDb(); return parent::_addDependenciesFromDb($data); } protected function _getUtilityCategoriesFromDb() { $select = $this->_db->select(); $select->from($this->_getPair('CompanyUtilityCategory'), ['utilityCategoryId']); $select->where('`CompanyUtilityCategory`.`companyId` = ?', $this->getPrimaryKey(), Qs_Db::INT_TYPE); return $this->_db->fetchCol($select); } protected function _getAssociateCategoriesFromDb() { $select = $this->_db->select(); $select->from($this->_getPair('CompanyAssociateCategory'), ['categoryId']); $select->where('`CompanyAssociateCategory`.`companyId` = ?', $this->getPrimaryKey(), Qs_Db::INT_TYPE); return $this->_db->fetchCol($select); } protected function _getSafetyGroupsFromDb() { $select = $this->_db->select(); $select->from($this->_getPair('CompanySafetyGroup'), ['safetyGroupId']); $select->where('`CompanySafetyGroup`.`companyId` = ?', $this->getPrimaryKey(), Qs_Db::INT_TYPE); return $this->_db->fetchCol($select); } protected function _getDistrictsFromDb() { $select = $this->_db->select(); $select->from( $this->_getPair('CompanyDistrict'), ['districtType', new Zend_Db_Expr('GROUP_CONCAT(`district` ORDER BY `district` SEPARATOR ", ")')] ); $select->where('`CompanyDistrict`.`companyId` = ?', $this->getPrimaryKey(), Qs_Db::INT_TYPE); $select->group('districtType'); return $this->_db->fetchPairs($select); } protected function _getPermissionsFromDb() { $select = $this->_db->select(); $select->from($this->_getPair('CompanyPermission'), ['userId']); $select->where('`CompanyPermission`.`companyId` = ?', $this->getPrimaryKey(), Qs_Db::INT_TYPE); return $this->_db->fetchCol($select); } protected function _getPositionsFromDb() { $select = $this->_db->select(); $select->from($this->_getPair('CompanyUtilityStaff')); $select->where('`CompanyUtilityStaff`.`companyId` = ?', $this->getPrimaryKey(), Qs_Db::INT_TYPE); $select->order('sorter'); return $this->_db->fetchAssoc($select); } public function getObjectInfo() { $data = parent::getObjectInfo(); if ($data) { $data['itemTitle'] = $data['name']; } return $data; } }