'LinkedIn URL', ]; use PreviousDataObjTrait; public function getPlaceholdersData() { /** @var $doc \App_Doc_User */ $doc = Zend_Registry::get('doc'); if ($doc->hasAuth()) { $id = $doc->getAuth()->getData('id'); $data = $this->_getFromDb($id); $data['nicknameOrFirstName'] = empty($data['nickname']) ? $data['firstName'] : $data['nickname']; $companyTypes = CompanyModel::getCompanyTypes(); $data['company']['type'] = $companyTypes[$data['company']['type']]; if ($data['company']['counties']) { $data['company']['counties'] = CompanyModel::getCountiesBy(['id' => $data['company']['counties']]); $data['company']['counties'] = implode(', ', $data['company']['counties']); } $data = Qs_Array::flattenAssoc($data, true); foreach ($this->_htmlPlaceholdersFields as $field) { if (!Qs_Array::get($data, $field)) { $data[$field] = '-'; } } $this->_setHtmlPlaceholdersData($data); } return parent::getPlaceholdersData(); } public function isLeadership($userId = null) { if (null === $userId) { $userId = $this->getPrimaryKey(); } $select = $this->_db->select(); $select->from($this->_getPair(), ['leadershipGroupId']); $select->where('`' . $this->_tableAlias . '`.`id` = ?', (string) $userId, Qs_Db::INT_TYPE); return (bool) $this->_db->fetchOne($select); } public function hasPermission($userId = null) { if (null === $userId) { $userId = $this->getPrimaryKey(); } if ($userId) { $select = $this->_db->select(); $select->from($this->_getPair('CompanyPermission'), [new Zend_Db_Expr('1')]); $select->where('`userId` = ?', (string) $userId, Qs_Db::INT_TYPE); $select->where('`companyId` = ?', (string) $this->_getFromDb($userId, 'companyId'), Qs_Db::INT_TYPE); return (bool) $this->_db->fetchOne($select); } return false; } protected function _addDependenciesFromDb(array &$data) { parent::_addDependenciesFromDb($data); $data['company'] = (new CompanyAdminObj())->setPrimaryKey($data['companyId'])->getData(); return $this; } protected function _updateDependency() { if ($this->_data['company']) { $this->_updateCompany(); } $this->_updateAddresses(); return $this; } protected function _updateCompany() { $companyId = $this->_getFromDb($this->getPrimaryKey(), 'companyId'); $data = $this->_data['company']; CompanyModel::prepareFormData($data); $companyTable = $this->_getTable('Company'); $currentData = $companyTable->findRow($companyId)->toArray(); $currentAddress = CompanyModel::createAddress4Geocoding($currentData); $newAddress = CompanyModel::createAddress4Geocoding($data); if ($currentAddress != $newAddress) { $geocoding = new Geocoding($newAddress); if ($geocoding->send()) { $response = $geocoding->getResponse(); $data = array_merge($data, $response->getLocation()); } else { $error = 'The geographical coordinates can\'t be determined ' . 'for the specified address criteria'; throw new Exception($error); } } $companyTable->updateByKey($data, $companyId); $where = $this->_db->quoteInto('`companyId` = ?', $companyId, Qs_Db::INT_TYPE); $this->_getTable('CompanyUtilityCategory')->delete($where); if (!empty($data['utilityCategoryId'])) { foreach ($data['utilityCategoryId'] as $utilityCategoryId) { $row = ['companyId' => $companyId, 'utilityCategoryId' => $utilityCategoryId]; $this->_getTable('CompanyUtilityCategory')->insert($row); } } $adminObj = new CompanyAdminObj(); $adminObj->saveAssociateCategories(Qs_Array::get($data, 'associateCategory', []), $companyId); CompanyModel::saveCounties(Qs_Array::get($data, 'counties', []), $companyId); unset($this->_companyData[$companyId]); return $this; } }