예제 #1
0
 public function testAttributesToAccountWithNoPostData()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $super = Yii::app()->user->userModel;
     $account = AccountTestHelper::createAccountByNameForOwner('Account2', $super);
     $contact = ContactTestHelper::createContactByNameForOwner('Contact2', $super);
     $contact->officePhone = '12345';
     $contact->officeFax = '12345';
     $saved = $contact->save();
     $this->assertTrue($saved);
     $account = LeadsUtil::attributesToAccountWithNoPostData($contact, $account, array('officeFax' => '15165'));
     $this->assertEquals($contact->officePhone, $account->officePhone);
     $this->assertNotEquals($contact->officeFax, $account->officeFax);
 }
 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 static function createAccountForLeadConversionFromAccountPostData($accountPostData, $contact, $controllerUtil)
 {
     if (isset($accountPostData['AccountSkip']) && $accountPostData['AccountSkip'] == true) {
         return null;
     } elseif (isset($accountPostData['SelectAccount']) && $accountPostData['SelectAccount'] == true) {
         $account = Account::getById(intval($accountPostData['accountId']));
         return $account;
     } elseif (isset($accountPostData['CreateAccount']) && $accountPostData['CreateAccount'] == true) {
         unset($accountPostData['CreateAccount']);
         $account = new Account();
         $account = LeadsUtil::attributesToAccountWithNoPostData($contact, $account, $accountPostData);
         $account = Yii::app()->custom->resolveLeadToAccountCustomAttributesWithNoPostData($contact, $account, $accountPostData);
         $savedSuccessfully = false;
         $modelToStringValue = null;
         $account = $controllerUtil->saveModelFromPost($accountPostData, $account, $savedSuccessfully, $modelToStringValue, false);
         if (!$account->getErrors()) {
             $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($contact);
             ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($account, $explicitReadWriteModelPermissions);
             if (!$account->save()) {
                 throw new NotSupportedException();
             }
             return $account;
         }
     }
 }
예제 #4
0
 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();
 }
예제 #5
0
 /**
  * @depends testAttributesToAccount
  */
 public function testAttributesToAccountWithNoPostData()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $postData = array('name' => '');
     $contacts = Contact::getByName('Super Man');
     $this->assertEquals(1, count($contacts));
     $contact = $contacts[0];
     $this->assertEquals('ABC Company', $contact->companyName);
     $this->assertEquals('1234567890', $contact->officePhone);
     $account = new Account();
     $this->assertEmpty($account->name);
     $this->assertEmpty($account->officePhone);
     $account = LeadsUtil::attributesToAccountWithNoPostData($contact, $account, $postData);
     $this->assertEquals('1234567890', $account->officePhone);
     $this->assertEquals(null, $account->name);
     $postData = array();
     $contacts = Contact::getByName('Super Man');
     $this->assertEquals(1, count($contacts));
     $contact = $contacts[0];
     $this->assertEquals('ABC Company', $contact->companyName);
     $this->assertEquals('1234567890', $contact->officePhone);
     $account = new Account();
     $this->assertEmpty($account->name);
     $this->assertEmpty($account->officePhone);
     $account = LeadsUtil::attributesToAccountWithNoPostData($contact, $account, $postData);
     $this->assertEquals('1234567890', $account->officePhone);
     $this->assertEquals('ABC Company', $account->name);
 }