public function varEnterpriseRowAndUserId() { $request = Zend_Controller_Front::getInstance()->getRequest(); $key = $request->getParam('id_key', $request->getParam('enterprise-id-key', $request->getParam('enterprise_id_key'))); if ($key) { //echo "-----1----"; $modelEnterprise = new Model_Enterprise(); $UserLocality = new Model_UserLocality(); $enterpriseIdKey = $key; $enterpriseRow = $modelEnterprise->getEnterpriseByIdKey($enterpriseIdKey); $enterpriseId = $enterpriseRow->getId(); $userLocalityGetEnterprise = $UserLocality->getUserLocalityByEnterpriseId($enterpriseRow->getId()); if (!$userLocalityGetEnterprise) { throw new Exception('Nenhum usuário relacionado nesta empresa.'); } $userId = $userLocalityGetEnterprise->getUserId(); } else { $enterpriseRow = Zend_Auth::getInstance()->getIdentity()->getEnterpriseRow(); $enterpriseId = $enterpriseRow['Id']; $userId = $enterpriseRow = Zend_Auth::getInstance()->getIdentity()->getUserId(); } return array('enterpriseId' => $enterpriseId, 'userId' => $userId); }
public function createUserMigrate($ficha) { $UserLocality = new Model_UserLocality(); $Acl = new Model_Acl(); // dados do usuário $registerUserData['login'] = $ficha['cpf']; $registerUserData['first_name'] = $ficha['first_name']; $registerUserData['surname'] = isset($ficha['surname']) ? $ficha['surname'] : null; $registerUserData['email'] = isset($ficha['email']) ? strtolower($ficha['email']) : "'null'"; $registerUserData['keypass'] = $ficha['keypass']; $registerUserData['keypass_confirm'] = $ficha['keypass']; $hasUL = $UserLocality->getUserLocalityByEnterpriseId($ficha['enterprise_id']); if ($hasUL) { return array('status' => true); } // start transaction externo Zend_Registry::get('db')->beginTransaction(); try { // ################################# $insertUser = $this->createUser($registerUserData); if (!$insertUser['status']) { throw new Vtx_UserException($insertUser['messageError']); } $registerUserLocalityData['user_id'] = $insertUser['lastInsertId']; $registerUserLocalityData['enterprise_id'] = $ficha['enterprise_id']; $insertUserLocality = $UserLocality->createUserLocality($registerUserLocalityData); if (!$insertUserLocality['status']) { throw new Vtx_UserException($insertUserLocality['messageError']); } $Acl->setUserRole($insertUser['lastInsertId'], Zend_Registry::get('config')->acl->roleEnterpriseId); // ################################# // fim da transaction Zend_Registry::get('db')->commit(); return array('status' => true); } catch (Vtx_UserException $e) { Zend_Registry::get('db')->rollBack(); return array('status' => false, 'messageError' => $e->getMessage()); } catch (Exception $e) { Zend_Registry::get('db')->rollBack(); throw new Exception($e); } }
public function getUserIdByIdKey($IdKey) { $enterpriseId = $this->getEnterpriseByIdKey($IdKey)->getId(); $modelUserLocality = new Model_UserLocality(); return $modelUserLocality->getUserLocalityByEnterpriseId($enterpriseId)->getUserId(); }
public function editAction() { $Acl = Zend_Registry::get('acl'); $auth = Zend_Auth::getInstance(); $User = new Model_User(); $President = new Model_President(); $PresidentProgram = new Model_PresidentProgram(); $modelLogCadastroEmpresa = new Model_LogCadastroEmpresa(); $UserLocality = new Model_UserLocality(); $AddressEnterprise = new Model_AddressEnterprise(); $AddressPresident = new Model_AddressPresident(); $this->_helper->viewRenderer->setRender('index'); $this->view->editStatus = false; $this->view->editByAdmin = false; if ($this->_getParam('id_key') and ($Acl->isAllowed($this->userLogged->getRole(), 'questionnaire:register', 'publisher') or $Acl->isAllowed($this->userLogged->getRole(), 'questionnaire:register', 'acompanhacadastro'))) { $enterpriseIdKey = $this->_getParam('id_key'); $enterpriseRow = $this->Enterprise->getEnterpriseByIdKey($enterpriseIdKey); $userLocalityGetEnterprise = $UserLocality->getUserLocalityByEnterpriseId($enterpriseRow->getId()); if (!$userLocalityGetEnterprise) { throw new Exception('Nenhum usuário relacionado nesta empresa.'); } $this->view->editStatus = true; $this->view->enterpriseIdKey = $enterpriseIdKey; $userId = $userLocalityGetEnterprise->getUserId(); $this->view->editByAdmin = true; } else { $userId = $this->userLogged->getUserId(); } $userRow = $User->getUserById($userId); $userLocalityRow = $UserLocality->getUserLocalityByUserId($userRow->getId()); $enterpriseRow = $this->Enterprise->getEnterpriseById($userLocalityRow->getEnterpriseId()); $presidentRow = $President->getPresidentByEnterpriseId($enterpriseRow->getId()); $addressPresidentRow = $AddressPresident->getAddressPresidentByPresidentId($presidentRow->getId()); $presidentProgramRow = $PresidentProgram->getAllPresidentProgramByPresidentId($presidentRow->getId()); $addressEnterpriseRow = $AddressEnterprise->getAddressEnterpriseByEnterpriseId($enterpriseRow->getId()); $logCadastradoPor = $modelLogCadastroEmpresa->getLogCadastroEmpresaByEnterpriseId($enterpriseRow->getId()); $cadastroNome = 'Site'; $cadastroCriadoEm = '00:00:00'; if ($logCadastradoPor) { if ($logCadastradoPor->getUserIdLog() != $userLocalityRow->getUserId()) { $cadastroNome = $User->getUserById($logCadastradoPor->getUserIdLog())->getFirstName(); } $cadastroCriadoEm = $logCadastradoPor->getCriadoEm(); } $this->view->logCadastroEmpresa = array('NomeCadastro' => $cadastroNome, 'CriadoEm' => $cadastroCriadoEm); if (!$enterpriseRow || !$presidentRow) { throw new Exception('Usuário inválido, não encontrado.'); } $this->view->userIdview = $userId; $this->view->enterpriseIdview = $enterpriseRow->getId(); // $modelQuest = new Model_Questionnaire(); // // $arrTerminoEtapas = $modelQuest->terminoEtapas($enterpriseRow, $userId); // // var_dump($arrTerminoEtapas); $this->view->getAllStates = $this->State->getAll(); if ($addressEnterpriseRow) { $this->view->getAllCities = $this->City->getAllCityByStateId($addressEnterpriseRow->getStateId()); //$this->view->getAllNeighborhoods = $this->Neighborhood->getAllNeighborhoodByCityId($addressEnterpriseRow->getCityId()); $this->view->getAllNeighborhoods = $addressEnterpriseRow->getCityId() ? $this->Neighborhood->getAllNeighborhoodByCityId($addressEnterpriseRow->getCityId()) : null; } if ($addressPresidentRow) { $this->view->getAllCitiesPresident = $this->City->getAllCityByStateId($addressPresidentRow->getStateId()); //$this->view->getAllNeighborhoodsPresident = $this->Neighborhood->getAllNeighborhoodByCityId($addressPresidentRow->getCityId()); $this->view->getAllNeighborhoodsPresident = $addressPresidentRow->getCityId() ? $this->Neighborhood->getAllNeighborhoodByCityId($addressPresidentRow->getCityId()) : null; } $this->view->getAllPositions = $this->Position->getAll(); $this->view->getAllEducations = $this->Education->getAll(); $this->view->getAllMetier = $this->Metier->getAll(); $this->view->getAllPresidentProgramType = $this->modelPresidentProgramType->getAll(); $this->view->hasECAC = $this->modelEnterpriseCategoryAwardCompetition->hasECAC($enterpriseRow->getId(), Zend_Registry::get('configDb')->competitionId); $hasntEmail = $enterpriseRow->getHasntEmail(); $hasntEmail = isset($hasntEmail) ? $hasntEmail : 1; $this->view->registerEnterpriseData = array('cnpj' => $enterpriseRow->getCnpj(), 'category_award_id' => $enterpriseRow->getCategoryAwardId(), 'category_sector_id' => $enterpriseRow->getCategorySectorId(), 'state_registration' => $enterpriseRow->getStateRegistration(), 'dap' => $enterpriseRow->getDap(), 'register_ministry_fisher' => $enterpriseRow->getRegisterMinistryFisher(), 'company_history' => $enterpriseRow->getCompanyHistory(), 'site' => $enterpriseRow->getSite(), 'status' => $enterpriseRow->getStatus(), 'social_name' => $enterpriseRow->getSocialName(), 'fantasy_name' => $enterpriseRow->getFantasyName(), 'creation_date' => $enterpriseRow->getCreationDate(), 'employees_quantity' => $enterpriseRow->getEmployeesQuantity(), 'phone' => $enterpriseRow->getPhone(), 'email_default' => $enterpriseRow->getEmailDefault(), 'annual_revenue' => $enterpriseRow->getAnnualRevenue(), 'cnae' => $enterpriseRow->getCnae(), 'nirf' => $enterpriseRow->getNirf(), 'farm_size' => $enterpriseRow->getFarmSize(), 'hasnt_email' => $hasntEmail); if ($addressEnterpriseRow) { $this->view->registerAddressEnterpriseData = array('cep' => $addressEnterpriseRow->getCep(), 'state_id' => $addressEnterpriseRow->getStateId(), 'city_id' => $addressEnterpriseRow->getCityId(), 'name_full_log' => $addressEnterpriseRow->getStreetNameFull(), 'street_number' => $addressEnterpriseRow->getStreetNumber(), 'street_completion' => $addressEnterpriseRow->getStreetCompletion(), 'neighborhood_id' => $addressEnterpriseRow->getNeighborhoodId()); } $this->view->registerPresidentData = array('enterprise_id' => $presidentRow->getEnterpriseId(), 'education_id' => $presidentRow->getEducationId(), 'position_id' => $presidentRow->getPositionId(), 'find_us_id' => $presidentRow->getFindUsId(), 'nick_name' => $presidentRow->getNickName(), 'cellphone' => $presidentRow->getCellphone(), 'newsletter_email' => $presidentRow->getNewsletterEmail(), 'newsletter_mail' => $presidentRow->getNewsletterMail(), 'newsletter_sms' => $presidentRow->getNewsletterSms(), 'agree' => $presidentRow->getAgree(), 'name' => $presidentRow->getName(), 'cpf' => $presidentRow->getCpf(), 'email' => $presidentRow->getEmail(), 'phone' => $presidentRow->getPhone(), 'born_date' => $presidentRow->getBornDate(), 'gender' => $presidentRow->getGender()); if ($addressPresidentRow) { $this->view->registerAddressPresidentData = array('cep' => $addressPresidentRow->getCep(), 'state_id' => $addressPresidentRow->getStateId(), 'city_id' => $addressPresidentRow->getCityId(), 'name_full_log' => $addressPresidentRow->getStreetNameFull(), 'street_number' => $addressPresidentRow->getStreetNumber(), 'street_completion' => $addressPresidentRow->getStreetCompletion(), 'neighborhood_id' => $addressPresidentRow->getNeighborhoodId()); } $this->view->registerPresidentProgramData = $presidentProgramRow; $this->view->registerUserData = array('first_name' => $userRow->getFirstName(), 'surname' => $userRow->getSurname(), 'password_hint' => $userRow->getPasswordHint()); $this->view->hasEligibility = $hasEligibility = $this->Enterprise->hasEligibilityRules($enterpriseRow->getIdKey()); if ($this->_getParam('forward', null) == true) { return; } if (!$this->getRequest()->isPost()) { return; } $ficha = $this->_getAllParams(); $ficha['log_empresa']['user_id_log'] = $this->userLogged->getUserId(); unset($this->view->editStatus); unset($this->view->getAllStates); unset($this->view->getAllCities); unset($this->view->getAllNeighborhoods); unset($this->view->getAllCitiesPresident); unset($this->view->getAllNeighborhoodsPresident); unset($this->view->getAllPositions); unset($this->view->getAllEducations); unset($this->view->getAllMetier); unset($this->view->getAllPresidentProgramType); unset($this->view->hasECAC); unset($this->view->registerEnterpriseData); unset($this->view->registerAddressEnterpriseData); unset($this->view->registerPresidentData); unset($this->view->registerAddressPresidentData); unset($this->view->registerPresidentProgramData); unset($this->view->registerUserData); unset($this->view->editByAdmin); // $this->view->registerData = $ficha; $updateEnterpriseTransaction = $this->Enterprise->updateEnterpriseTransaction($ficha, $enterpriseRow, $addressEnterpriseRow, $presidentRow, $addressPresidentRow, $userRow); if (!$updateEnterpriseTransaction['status']) { $this->view->messageError = $updateEnterpriseTransaction['messageError']; $this->view->errorCode = $updateEnterpriseTransaction['errorCode']; return; } $this->view->itemSuccess = true; $emailEnterprise = isset($ficha['enterprise']['email_default']) ? $ficha['enterprise']['email_default'] : ''; $socialName = $ficha['enterprise']['social_name']; $cnpj = $ficha['enterprise']['cnpj']; if ($this->view->itemSuccess && ($emailEnterprise == null || $emailEnterprise == '')) { $stateId = $ficha['addressEnterprise']['state_id']; $this->sendWhiteListMail($stateId, $socialName, $cnpj); } $hasEligibility = $this->Enterprise->hasEligibilityRules($enterpriseRow->getIdKey()); if ($Acl->isAllowed($auth->getIdentity()->getRole(), 'questionnaire:register', 'publisher')) { $this->view->loadUrlRegister = $this->view->baseUrl('/management/enterprise/success/itemEditSuccess/true/social_name/' . urlencode($ficha['enterprise']['social_name']) . '/enterpriseIdKey/' . $enterpriseIdKey . '/hasEligibility/' . $hasEligibility); return; } if ($Acl->isAllowed($auth->getIdentity()->getRole(), 'questionnaire:register', 'index')) { $this->view->loadUrlRegister = $this->view->baseUrl('/questionnaire/register/success/itemEditSuccess/true/hasEligibility/' . $hasEligibility); return; } }