public function actionConvert($id) { assert('!empty($id)'); LeadsUtil::removeFromSession(LeadsUtil::LEAD_CONVERSION_ACCOUNT_DATA_SESSION_KEY); $contact = Contact::getById(intval($id)); if (!LeadsUtil::isStateALead($contact->state)) { $urlParams = array('/contacts/' . $this->getId() . '/details', 'id' => $contact->id); $this->redirect($urlParams); } $convertToAccountSetting = LeadsModule::getConvertToAccountSetting(); $selectAccountForm = new AccountSelectForm(); $account = new Account(); ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($contact); $userCanAccessContacts = RightsUtil::canUserAccessModule('ContactsModule', Yii::app()->user->userModel); $userCanAccessAccounts = RightsUtil::canUserAccessModule('AccountsModule', Yii::app()->user->userModel); $userCanCreateAccount = RightsUtil::doesUserHaveAllowByRightName('AccountsModule', AccountsModule::RIGHT_CREATE_ACCOUNTS, Yii::app()->user->userModel); LeadsControllerSecurityUtil::resolveCanUserProperlyConvertLead($userCanAccessContacts, $userCanAccessAccounts, $convertToAccountSetting); if (isset($_POST['AccountSelectForm'])) { $selectAccountForm->setAttributes($_POST['AccountSelectForm']); if ($selectAccountForm->validate()) { $account = Account::getById(intval($selectAccountForm->accountId)); $accountPostData = array('accountId' => intval($selectAccountForm->accountId), 'SelectAccount' => true); LeadsUtil::storeIntoSession(LeadsUtil::LEAD_CONVERSION_ACCOUNT_DATA_SESSION_KEY, $accountPostData); $this->redirect(array('/leads/default/convertFinal', 'id' => $contact->id)); } } elseif (isset($_POST['Account'])) { $account = LeadsUtil::attributesToAccountWithNoPostData($contact, $account, $_POST['Account']); $savedSuccessfully = false; $modelToStringValue = null; $postData = $_POST['Account']; $controllerUtil = static::getZurmoControllerUtil(); $account = $controllerUtil->saveModelFromPost($postData, $account, $savedSuccessfully, $modelToStringValue, true); if (!$account->getErrors()) { $accountPostData = $postData; $accountPostData['CreateAccount'] = true; LeadsUtil::storeIntoSession(LeadsUtil::LEAD_CONVERSION_ACCOUNT_DATA_SESSION_KEY, $accountPostData); $this->redirect(array('/leads/default/convertFinal', 'id' => $contact->id)); } } elseif (isset($_POST['AccountSkip']) || $convertToAccountSetting == LeadsModule::CONVERT_NO_ACCOUNT || $convertToAccountSetting == LeadsModule::CONVERT_ACCOUNT_NOT_REQUIRED && !$userCanAccessAccounts) { $accountPostData = array('AccountSkip' => true); LeadsUtil::storeIntoSession(LeadsUtil::LEAD_CONVERSION_ACCOUNT_DATA_SESSION_KEY, $accountPostData); $this->redirect(array('/leads/default/convertFinal', 'id' => $contact->id)); } else { $account = LeadsUtil::attributesToAccount($contact, $account); } $progressBarAndStepsView = new LeadConversionStepsAndProgressBarForWizardView(); $convertView = new LeadConvertView($this->getId(), $this->getModule()->getId(), $contact->id, strval($contact), $selectAccountForm, $account, $convertToAccountSetting, $userCanCreateAccount); $view = new LeadsPageView(ZurmoDefaultViewUtil::makeTwoStandardViewsForCurrentUser($this, $progressBarAndStepsView, $convertView)); echo $view->render(); }
public function actionConvert($id) { assert('!empty($id)'); $contact = Contact::getById(intval($id)); if (!LeadsUtil::isStateALead($contact->state)) { $urlParams = array('/contacts/' . $this->getId() . '/details', 'id' => $contact->id); $this->redirect($urlParams); } $convertToAccountSetting = LeadsModule::getConvertToAccountSetting(); $selectAccountForm = new AccountSelectForm(); $account = new Account(); ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($contact); $userCanAccessContacts = RightsUtil::canUserAccessModule('ContactsModule', Yii::app()->user->userModel); $userCanAccessAccounts = RightsUtil::canUserAccessModule('AccountsModule', Yii::app()->user->userModel); $userCanCreateAccount = RightsUtil::doesUserHaveAllowByRightName('AccountsModule', AccountsModule::RIGHT_CREATE_ACCOUNTS, Yii::app()->user->userModel); LeadsControllerSecurityUtil::resolveCanUserProperlyConvertLead($userCanAccessContacts, $userCanAccessAccounts, $convertToAccountSetting); if (isset($_POST['AccountSelectForm'])) { $selectAccountForm->setAttributes($_POST['AccountSelectForm']); if ($selectAccountForm->validate()) { $account = Account::getById(intval($selectAccountForm->accountId)); $this->actionSaveConvertedContact($contact, $account); } } elseif (isset($_POST['Account'])) { $account = LeadsUtil::attributesToAccountWithNoPostData($contact, $account, $_POST['Account']); $account->setAttributes($_POST['Account']); if ($account->save()) { $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($contact); ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($account, $explicitReadWriteModelPermissions); if (!$account->save()) { throw new NotSupportedException(); } $this->actionSaveConvertedContact($contact, $account); } } elseif (isset($_POST['AccountSkip']) || $convertToAccountSetting == LeadsModule::CONVERT_NO_ACCOUNT || $convertToAccountSetting == LeadsModule::CONVERT_ACCOUNT_NOT_REQUIRED && !$userCanAccessAccounts) { $this->actionSaveConvertedContact($contact); } else { $account = LeadsUtil::attributesToAccount($contact, $account); } $convertView = new LeadConvertView($this->getId(), $this->getModule()->getId(), $contact->id, strval($contact), $selectAccountForm, $account, $convertToAccountSetting, $userCanCreateAccount); $view = new LeadsPageView(ZurmoDefaultViewUtil::makeStandardViewForCurrentUser($this, $convertView)); echo $view->render(); }