/** * @param RedBeanModel $model * @return null */ public static function getModuleClassNameByModel(RedBeanModel $model) { if (!LeadsUtil::isStateALead($model->state)) { return 'ContactsModule'; } return 'LeadsModule'; }
protected static function resolveModuleClassName($attribute, ReportResultsRowData $data) { if (get_class($data->getModel($attribute)) == 'Contact' && LeadsUtil::isStateALead($data->getModel($attribute)->state)) { return 'LeadsModule'; } else { return $data->getModel($attribute)->getModuleClassName(); } }
protected function makeNonEditableLinkUrl() { if (LeadsUtil::isStateALead($this->resolveState())) { $moduleId = 'leads'; } else { $moduleId = static::$moduleId; } return Yii::app()->createUrl($moduleId . '/' . $this->controllerId . '/details/', array('id' => $this->model->{$this->attribute}->id)); }
/** * Special handling for modules that use 'states' for their models. Currently only the Contacts/Leads modules * have this characteristic. This method will need to be expanding to dynamically inspect the modules and * resolve the state information without needing a hard coded if clause asking if the module class name is * 'Contacts'. * @return string of the module directory name. */ public static function resolveModuleClassNameByStateOfModel(RedBeanModel $model) { $modelClassName = get_class($model); $moduleClassName = $modelClassName::getModuleClassName(); if ($moduleClassName == 'ContactsModule') { if (LeadsUtil::isStateALead($model->state)) { return 'LeadsModule'; } } return $moduleClassName; }
public function scoreOnSaveModel(CEvent $event) { if (Yii::app()->gameHelper->isScoringModelsOnSaveMuted()) { return; } if (!LeadsUtil::isStateALead($event->sender->state) && array_key_exists('state', $event->sender->originalAttributeValues) && $event->sender->originalAttributeValues['state'][1] > 0 && LeadsUtil::isStateALeadByStateName($event->sender->originalAttributeValues['state'][2])) { $this->scoreOnSaveWhereLeadIsConverted($event); } elseif (LeadsUtil::isStateALead($event->sender->state)) { $this->scoreOnSaveWhereStateIsLead($event); } else { parent::scoreOnSaveModel($event); } }
public static function createLeadWithAccountByNameForOwner($firstName, $owner, $account) { ContactsModule::loadStartingData(); $contact = new Contact(); $contact->firstName = $firstName; $contact->lastName = $firstName . 'son'; $contact->owner = $owner; $contact->account = $account; $contact->state = LeadsUtil::getStartingState(); $saved = $contact->save(); assert('$saved'); return $contact; }
public function testSuperUserCompleteMatchVariations() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/matchingList'); $message1 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $message2 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $message3 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $contact = ContactTestHelper::createContactByNameForOwner('gail', $super); $startingContactState = ContactsUtil::getStartingState(); $startingLeadState = LeadsUtil::getStartingState(); //test validating selecting an existing contact $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'select-contact-form-' . $message1->id, 'AnyContactSelectForm' => array($message1->id => array('contactId' => $contact->id, 'contactName' => 'Some Name')))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test validating creating a new contact $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'contact-inline-create-form-' . $message1->id, 'Contact' => array($message1->id => array('firstName' => 'Gail', 'lastName' => 'Green', 'officePhone' => '456765421', 'state' => array('id' => $startingContactState->id))))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test validating creating a new lead $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'lead-inline-create-form-' . $message1->id, 'Lead' => array($message1->id => array('firstName' => 'Gail', 'lastName' => 'Green', 'officePhone' => '456765421', 'state' => array('id' => $startingLeadState->id))))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test selecting existing contact and saving $this->assertNull($contact->primaryEmail->emailAddress); $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('AnyContactSelectForm' => array($message1->id => array('contactId' => $contact->id, 'contactName' => 'Some Name')))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $this->assertEquals('*****@*****.**', $contact->primaryEmail->emailAddress); $this->assertTrue($message1->sender->personOrAccount->isSame($contact)); $this->assertEquals('Archived', $message1->folder); //test creating new contact and saving $this->assertEquals(1, Contact::getCount()); $this->setGetArray(array('id' => $message2->id)); $this->setPostArray(array('Contact' => array($message2->id => array('firstName' => 'George', 'lastName' => 'Patton', 'officePhone' => '456765421', 'state' => array('id' => $startingContactState->id))))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $this->assertEquals(2, Contact::getCount()); $contacts = Contact::getByName('George Patton'); $contact = $contacts[0]; $this->assertTrue($message2->sender->personOrAccount->isSame($contact)); $this->assertEquals('Archived', $message2->folder); //test creating new lead and saving $this->assertEquals(2, Contact::getCount()); $this->setGetArray(array('id' => $message3->id)); $this->setPostArray(array('Lead' => array($message3->id => array('firstName' => 'Billy', 'lastName' => 'Kid', 'officePhone' => '456765421', 'state' => array('id' => $startingLeadState->id))))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $this->assertEquals(3, Contact::getCount()); $contacts = Contact::getByName('Billy Kid'); $contact = $contacts[0]; $this->assertTrue($message3->sender->personOrAccount->isSame($contact)); $this->assertEquals('Archived', $message3->folder); }
public static function makeNewLeadsReport() { $leadStateIdsAndNames = LeadsUtil::getLeadStateDataFromStartingStateOnAndKeyedById(); $report = new Report(); $report->setDescription('A report showing new leads'); $report->setModuleClassName('ContactsModule'); $report->setName('New Leads Report'); $report->setType(Report::TYPE_ROWS_AND_COLUMNS); $report->setOwner(Yii::app()->user->userModel); $report->setFiltersStructure('1 AND 2'); $report->setCurrencyConversionType(Report::CURRENCY_CONVERSION_TYPE_BASE); $filter = new FilterForReportForm('ContactsModule', 'Contact', $report->getType()); $filter->attributeIndexOrDerivedType = 'createdDateTime'; $filter->valueType = MixedDateTypesSearchFormAttributeMappingRules::TYPE_LAST_7_DAYS; $filter->availableAtRunTime = true; $report->addFilter($filter); $filterValue = array(); foreach (array_keys($leadStateIdsAndNames) as $value) { $filterValue[] = (string) $value; } $filter = new FilterForReportForm('ContactsModule', 'Contact', $report->getType()); $filter->attributeIndexOrDerivedType = 'state'; $filter->value = $filterValue; $filter->operator = OperatorRules::TYPE_ONE_OF; $report->addFilter($filter); $displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact', $report->getType()); $displayAttribute->attributeIndexOrDerivedType = 'FullName'; $report->addDisplayAttribute($displayAttribute); $displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact', $report->getType()); $displayAttribute->attributeIndexOrDerivedType = 'source'; $report->addDisplayAttribute($displayAttribute); $displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact', $report->getType()); $displayAttribute->attributeIndexOrDerivedType = 'officePhone'; $report->addDisplayAttribute($displayAttribute); $displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact', $report->getType()); $displayAttribute->attributeIndexOrDerivedType = 'primaryEmail___emailAddress'; $report->addDisplayAttribute($displayAttribute); $savedReport = new SavedReport(); SavedReportToReportAdapter::resolveReportToSavedReport($report, $savedReport); //set explicit $saved = $savedReport->save(); assert('$saved'); $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReport); $explicitReadWriteModelPermissions->addReadWritePermitable(Group::getByName(Group::EVERYONE_GROUP_NAME)); $success = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($savedReport, $explicitReadWriteModelPermissions); assert('$success'); $saved = $savedReport->save(); assert('$saved'); }
/** * Get states by type. * @param string $state * @throws ApiException */ protected function sendStatesByLeadOrContact($state = 'contact') { try { $states = array(); if ($state == 'contact') { $states = ContactsUtil::getContactStateDataFromStartingStateLabelByLanguage(Yii::app()->language); } elseif ($state == 'lead') { $states = LeadsUtil::getLeadStateDataFromStartingStateLabelByLanguage(Yii::app()->language); } foreach ($states as $model) { $data['items'][] = static::getModelToApiDataUtilData($model); } $data['totalCount'] = count($data['items']); $data['currentPage'] = 1; $result = new ApiResult(ApiResponse::STATUS_SUCCESS, $data, null, null); Yii::app()->apiHelper->sendResponse($result); } catch (Exception $e) { $message = $e->getMessage(); throw new ApiException($message); } }
/** * @depends testSuperUserCreateAction */ public function testSuperUserConvertAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $startingLeadState = LeadsUtil::getStartingState(); $startingContactState = ContactsUtil::getStartingState(); $leads = Contact::getByName('myNewLead myNewLeadson'); $this->assertEquals(1, count($leads)); $lead = $leads[0]; $this->assertTrue($lead->state == $startingLeadState); //Test just going to the convert page. $this->setGetArray(array('id' => $lead->id)); $this->resetPostArray(); //Test trying to convert by skipping account creation $this->runControllerWithNoExceptionsAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $lead->id)); $this->setPostArray(array('AccountSkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $leadId = $lead->id; $lead->forget(); $contact = Contact::getById($leadId); $this->assertTrue($contact->state == $startingContactState); //Test trying to convert by creating a new account. $lead5 = LeadTestHelper::createLeadbyNameForOwner('superLead5', $super); $this->assertTrue($lead5->state == $startingLeadState); $this->setGetArray(array('id' => $lead5->id)); $this->setPostArray(array('Account' => array('name' => 'someAccountName'))); $this->assertEquals(0, count(Account::getAll())); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->assertEquals(1, count(Account::getAll())); $lead5Id = $lead5->id; $lead5->forget(); $contact5 = Contact::getById($lead5Id); $this->assertTrue($contact5->state == $startingContactState); $this->assertEquals('someAccountName', $contact5->account->name); //Test trying to convert by selecting an existing account $account = AccountTestHelper::createAccountbyNameForOwner('someNewAccount', $super); $lead6 = LeadTestHelper::createLeadbyNameForOwner('superLead6', $super); $this->assertTrue($lead6->state == $startingLeadState); $this->setGetArray(array('id' => $lead6->id)); $this->setPostArray(array('AccountSelectForm' => array('accountId' => $account->id, 'accountName' => 'someNewAccount'))); $this->assertEquals(2, count(Account::getAll())); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->assertEquals(2, count(Account::getAll())); $lead6Id = $lead6->id; $lead6->forget(); $contact6 = Contact::getById($lead6Id); $this->assertTrue($contact6->state == $startingContactState); $this->assertEquals($account, $contact6->account); }
protected function getDropDownArray() { return LeadsUtil::getLeadStateDataFromStartingStateKeyedByIdAndLabelByLanguage(Yii::app()->language); }
protected function resolveStates() { return LeadsUtil::getLeadStateDataFromStartingStateOnAndKeyedById(); }
/** * @depends testApiServerUrl */ public function testCreateLead() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); $industryValues = array('Automotive', 'Adult Entertainment', 'Financial Services', 'Mercenaries & Armaments'); $industryFieldData = CustomFieldData::getByName('Industries'); $industryFieldData->serializedData = serialize($industryValues); $this->assertTrue($industryFieldData->save()); $sourceValues = array('Word of Mouth', 'Outbound', 'Trade Show'); $sourceFieldData = CustomFieldData::getByName('LeadSources'); $sourceFieldData->serializedData = serialize($sourceValues); $this->assertTrue($sourceFieldData->save()); $titles = array('Mr.', 'Mrs.', 'Ms.', 'Dr.', 'Swami'); $customFieldData = CustomFieldData::getByName('Titles'); $customFieldData->serializedData = serialize($titles); $this->assertTrue($customFieldData->save()); $this->assertEquals(6, count(ContactState::GetAll())); $contactStates = ContactState::GetAll(); $primaryEmail['emailAddress'] = "*****@*****.**"; $primaryEmail['optOut'] = 1; $secondaryEmail['emailAddress'] = "*****@*****.**"; $secondaryEmail['optOut'] = 0; $secondaryEmail['isInvalid'] = 1; $primaryAddress['street1'] = '129 Noodle Boulevard'; $primaryAddress['street2'] = 'Apartment 6000A'; $primaryAddress['city'] = 'Noodleville'; $primaryAddress['postalCode'] = '23453'; $primaryAddress['country'] = 'The Good Old US of A'; $secondaryAddress['street1'] = '25 de Agosto 2543'; $secondaryAddress['street2'] = 'Local 3'; $secondaryAddress['city'] = 'Ciudad de Los Fideos'; $secondaryAddress['postalCode'] = '5123-4'; $secondaryAddress['country'] = 'Latinoland'; $account = new Account(); $account->name = 'Some Account'; $account->owner = $super; $this->assertTrue($account->save()); $data['firstName'] = "Michael"; $data['lastName'] = "Smith"; $data['jobTitle'] = "President"; $data['department'] = "Sales"; $data['officePhone'] = "653-235-7824"; $data['mobilePhone'] = "653-235-7821"; $data['officeFax'] = "653-235-7834"; $data['description'] = "Some desc."; $data['companyName'] = "Michael Co"; $data['website'] = "http://sample.com"; $data['industry']['value'] = $industryValues[2]; $data['source']['value'] = $sourceValues[1]; $data['title']['value'] = $titles[3]; $data['state']['id'] = LeadsUtil::getStartingState()->id; $data['account']['id'] = $account->id; $data['primaryEmail'] = $primaryEmail; $data['secondaryEmail'] = $secondaryEmail; $data['primaryAddress'] = $primaryAddress; $data['secondaryAddress'] = $secondaryAddress; $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/create/', 'POST', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $data['owner'] = array('id' => $super->id, 'username' => 'super'); $data['createdByUser'] = array('id' => $super->id, 'username' => 'super'); $data['modifiedByUser'] = array('id' => $super->id, 'username' => 'super'); // We need to unset some empty values from response. unset($response['data']['createdDateTime']); unset($response['data']['modifiedDateTime']); unset($response['data']['primaryEmail']['id']); unset($response['data']['primaryEmail']['isInvalid']); unset($response['data']['secondaryEmail']['id']); unset($response['data']['primaryAddress']['id']); unset($response['data']['primaryAddress']['state']); unset($response['data']['primaryAddress']['longitude']); unset($response['data']['primaryAddress']['latitude']); unset($response['data']['primaryAddress']['invalid']); unset($response['data']['secondaryAddress']['id']); unset($response['data']['secondaryAddress']['state']); unset($response['data']['secondaryAddress']['longitude']); unset($response['data']['secondaryAddress']['latitude']); unset($response['data']['secondaryAddress']['invalid']); unset($response['data']['industry']['id']); unset($response['data']['source']['id']); unset($response['data']['title']['id']); unset($response['data']['id']); unset($response['data']['googleWebTrackingId']); ksort($data); ksort($response['data']); $this->assertEquals($data, $response['data']); }
protected static function makeStatesDataAndLabels() { return LeadsUtil::getLeadStateDataFromStartingStateKeyedByIdAndLabelByLanguage(Yii::app()->language); }
public function testSuperUserCompleteMatchVariations() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/matchingList'); $message1 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $message1Id = $message1->id; $message2 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $message2Id = $message2->id; $message3 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $contact = ContactTestHelper::createContactByNameForOwner('gail', $super); $startingContactState = ContactsUtil::getStartingState(); $startingLeadState = LeadsUtil::getStartingState(); //test validating selecting an existing contact $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'select-contact-form-' . $message1->id, 'AnyContactSelectForm' => array($message1->id => array('contactId' => $contact->id, 'contactName' => 'Some Name')))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test validating creating a new contact $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'contact-inline-create-form-' . $message1->id, 'Contact' => array($message1->id => array('firstName' => 'Gail', 'lastName' => 'Green', 'officePhone' => '456765421', 'state' => array('id' => $startingContactState->id))))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test validating creating a new lead $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'lead-inline-create-form-' . $message1->id, 'Lead' => array($message1->id => array('firstName' => 'Gail', 'lastName' => 'Green', 'officePhone' => '456765421', 'state' => array('id' => $startingLeadState->id))))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test selecting existing contact and saving $this->assertNull($contact->primaryEmail->emailAddress); $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('AnyContactSelectForm' => array($message1->id => array('contactId' => $contact->id, 'contactName' => 'Some Name')))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $message1->forget(); $message1 = EmailMessage::getById($message1Id); $this->assertNull($contact->primaryEmail->emailAddress); $this->assertCount(1, $message1->sender->personsOrAccounts); $this->assertTrue($message1->sender->personsOrAccounts[0]->isSame($contact)); $this->assertEquals('Archived', $message1->folder); //assert subject of the email going to edit. $this->setGetArray(array('id' => $contact->id)); $this->runControllerWithNoExceptionsAndGetContent('contacts/default/details'); $this->assertEquals('A test unmatched archived received email', $message1->subject); //edit subject of email message. $this->setGetArray(array('id' => $message1->id)); $createEmailMessageFormData = array('subject' => 'A test unmatched archived received email edited'); $this->setPostArray(array('ajax' => 'edit-form', 'EmailMessage' => $createEmailMessageFormData)); $this->runControllerWithRedirectExceptionAndGetUrl('emailMessages/default/edit'); //assert subject is edited or not. $this->setGetArray(array('id' => $contact->id)); $this->runControllerWithNoExceptionsAndGetContent('contacts/default/details'); $this->assertEquals('A test unmatched archived received email edited', $message1->subject); //delete email message. $this->setGetArray(array('id' => $message1->id)); $this->runControllerWithRedirectExceptionAndGetUrl('emailMessages/default/delete', true); //assert subject not present. try { EmailMessage::getById($message1->id); $this->fail(); } catch (NotFoundException $e) { //success } //Test the default permission was setted $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($message1); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]); //test creating new contact and saving $this->assertEquals(1, Contact::getCount()); $this->setGetArray(array('id' => $message2->id)); $this->setPostArray(array('Contact' => array($message2->id => array('firstName' => 'George', 'lastName' => 'Patton', 'officePhone' => '456765421', 'state' => array('id' => $startingContactState->id))))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $message2->forget(); $message2 = EmailMessage::getById($message2Id); $this->assertEquals(2, Contact::getCount()); $contacts = Contact::getByName('George Patton'); $contact = $contacts[0]; $this->assertCount(1, $message2->sender->personsOrAccounts); $this->assertTrue($message2->sender->personsOrAccounts[0]->isSame($contact)); $this->assertEquals('Archived', $message2->folder); //Test the default permission was setted $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($message2); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]); //test creating new lead and saving $this->assertEquals(2, Contact::getCount()); $this->setGetArray(array('id' => $message3->id)); $this->setPostArray(array('Lead' => array($message3->id => array('firstName' => 'Billy', 'lastName' => 'Kid', 'officePhone' => '456765421', 'state' => array('id' => $startingLeadState->id))))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $this->assertEquals(3, Contact::getCount()); $contacts = Contact::getByName('Billy Kid'); $contact = $contacts[0]; $this->assertCount(1, $message3->sender->personsOrAccounts); $this->assertTrue($message3->sender->personsOrAccounts[0]->isSame($contact)); $this->assertEquals('Archived', $message3->folder); //Test the default permission was setted $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($message3); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]); }
public function testLeadsStateMetadataAdapterWithNoStates() { $metadata = ContactsModule::getMetadata(); $metadata['global']['startingStateId'] = LeadsUtil::getStartingState()->id; ContactsModule::setMetadata($metadata); $adapter = new LeadsStateMetadataAdapter(array('clauses' => array(), 'structure' => '')); $adaptedMetadata = $adapter->getAdaptedDataProviderMetadata(); $compareMetadata = array('clauses' => array(1 => array('attributeName' => 'state', 'operatorType' => 'equals', 'value' => '-1')), 'structure' => '(1)'); $this->assertEquals($compareMetadata, $adaptedMetadata); }
public function actionDelete($id) { $contact = Contact::GetById(intval($id)); ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($contact); if (!LeadsUtil::isStateALead($contact->state)) { $urlParams = array('/contacts/' . $this->getId() . '/delete', 'id' => $contact->id); $this->redirect($urlParams); } else { $contact->delete(); $this->redirect(array($this->getId() . '/index')); } }
/** * @depends testSuperUserCreateAction */ public function testSuperUserConvertAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $startingLeadState = LeadsUtil::getStartingState(); $startingContactState = ContactsUtil::getStartingState(); $leads = Contact::getByName('myNewLead myNewLeadson'); $this->assertEquals(1, count($leads)); $lead = $leads[0]; $this->assertTrue($lead->state == $startingLeadState); //Test just going to the convert page. $this->setGetArray(array('id' => $lead->id)); $this->resetPostArray(); //Test trying to convert by skipping account creation and by skipping opportunity creation $this->runControllerWithNoExceptionsAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $lead->id)); $this->setPostArray(array('AccountSkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $lead->id)); $this->setPostArray(array('OpportunitySkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convertFinal'); $leadId = $lead->id; $lead->forget(); $contact = Contact::getById($leadId); $this->assertTrue($contact->state == $startingContactState); //Test trying to convert by creating a new account and by skipping opportunity creation. $lead5 = LeadTestHelper::createLeadbyNameForOwner('superLead5', $super); $this->assertTrue($lead5->state == $startingLeadState); $this->setGetArray(array('id' => $lead5->id)); $this->setPostArray(array('Account' => array('name' => 'someAccountName'))); $this->assertEquals(0, Account::getCount()); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $lead5->id)); $this->setPostArray(array('OpportunitySkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convertFinal'); $this->assertEquals(1, Account::getCount()); $lead5Id = $lead5->id; $lead5->forget(); $contact5 = Contact::getById($lead5Id); $this->assertTrue($contact5->state == $startingContactState); $this->assertEquals('someAccountName', $contact5->account->name); //Test trying to convert by selecting an existing account and by skipping opportunity creation. $account = AccountTestHelper::createAccountbyNameForOwner('someNewAccount', $super); $lead6 = LeadTestHelper::createLeadbyNameForOwner('superLead6', $super); $this->assertTrue($lead6->state == $startingLeadState); $this->setGetArray(array('id' => $lead6->id)); $this->setPostArray(array('AccountSelectForm' => array('accountId' => $account->id, 'accountName' => 'someNewAccount'))); $this->assertEquals(2, Account::getCount()); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $lead6->id)); $this->setPostArray(array('OpportunitySkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convertFinal'); $this->assertEquals(2, Account::getCount()); $lead6Id = $lead6->id; $lead6->forget(); $contact6 = Contact::getById($lead6Id); $this->assertTrue($contact6->state == $startingContactState); $this->assertEquals($account, $contact6->account); //Test trying to convert by skipping account creation and by creating new opportunity $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $leadOpp = LeadTestHelper::createLeadbyNameForOwner('superLeadOpp', $super); $this->setGetArray(array('id' => $leadOpp->id)); $this->setPostArray(array('AccountSkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $leadOpp->id)); $this->setPostArray(array('Opportunity' => array('name' => 'someOpportunityName', 'amount' => array('currency' => array('id' => '1'), 'value' => '100'), 'closeDate' => '6/19/2014', 'stage' => array('value' => 'Negotiating'), 'probability' => '50'))); $this->assertEquals(0, Opportunity::getCount()); $this->assertEquals(2, Account::getCount()); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convertFinal'); $leadId = $leadOpp->id; $leadOpp->forget(); $contact = Contact::getById($leadId); $this->assertTrue($contact->state == $startingContactState); $this->assertEquals(1, Opportunity::getCount()); $this->assertEquals(2, Account::getCount()); }
/** * @param Contact $contact * @return string */ protected static function resolveModuleClassName(Contact $contact) { if (LeadsUtil::isStateALead($contact->state)) { return 'LeadsModule'; } else { return $contact->getModuleClassName(); } }
public static function getResolvedModuleIdForContactWebFormEntry(Contact $contact) { if (LeadsUtil::isStateALead($contact->state)) { return 'leads'; } return 'contacts'; }
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; } } }
protected function renderGoToDetailsLink() { if ($this->haveGoToDetailsLink) { if (get_class($this->model) == 'User') { $link = Yii::app()->createUrl('users/default/details/', array('id' => $this->model->id)); } elseif (LeadsUtil::isStateALead($this->model->state)) { $link = Yii::app()->createUrl('leads/default/details/', array('id' => $this->model->id)); } else { $link = Yii::app()->createUrl('contacts/default/details/', array('id' => $this->model->id)); } return ZurmoHtml::link(Zurmo::t('ZurmoModule', 'Go To Details'), $link, array('class' => 'simple-link', 'target' => '_blank')); } }
/** * @depends testSuperUserCreateFromRelationAction */ public function testSuperUserCopyAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $contacts = Contact::getByName('myNewContact myNewContactson'); $this->assertCount(1, $contacts); $postArray = array('Contact' => array('firstName' => 'myNewContact', 'lastName' => 'myNewContactson', 'jobTitle' => 'job title', 'account' => array('name' => 'Linked account'), 'department' => 'Some department', 'officePhone' => '456765421', 'mobilePhone' => '958462315', 'officeFax' => '123456789', 'primaryEmail' => array('emailAddress' => '*****@*****.**'), 'secondaryEmail' => array('emailAddress' => '*****@*****.**'), 'primaryAddress' => array('street1' => 'Street1', 'street2' => 'Street2', 'city' => 'City', 'state' => 'State', 'postalCode' => '12345', 'country' => 'Country'), 'secondaryAddress' => array('street1' => 'Street1', 'street2' => 'Street2', 'city' => 'City', 'state' => 'State', 'postalCode' => '12345', 'country' => 'Country'), 'description' => 'some description')); $this->updateModelValuesFromPostArray($contacts[0], $postArray); $this->assertModelHasValuesFromPostArray($contacts[0], $postArray); $this->assertTrue($contacts[0]->save()); $this->assertTrue($this->checkCopyActionResponseAttributeValuesFromPostArray($contacts[0], $postArray)); $postArray['Contact']['firstName'] = 'myClonedContact'; $postArray['Contact']['lastName'] = 'myClonedContactson'; $postArray['Contact']['state'] = array('id' => LeadsUtil::getStartingState()->id); $this->setGetArray(array('id' => $contacts[0]->id)); $this->setPostArray($postArray); $this->runControllerWithRedirectExceptionAndGetUrl('contacts/default/copy'); $contacts = Contact::getByName('myClonedContact myClonedContactson'); $this->assertCount(1, $contacts); $this->assertTrue($contacts[0]->owner->isSame($super)); unset($postArray['Contact']['state']); $this->assertModelHasValuesFromPostArray($contacts[0], $postArray); $contacts = Contact::getAll(); $this->assertCount(15, $contacts); $contacts = Contact::getByName('myClonedContact myClonedContactson'); $this->assertCount(1, $contacts); $this->assertTrue($contacts[0]->delete()); }
/** * If contact is lead then just return companyName field * If contact is contact and do not have related account, return company name * If contact is contact and have related account, return account name * @param Contact $contact * @return string */ public static function resolveCompanyNameForRelatedAccountName(Contact $contact) { if (LeadsUtil::isStateALead($contact->state) || !isset($contact->account) || $contact->account->id <= 0) { return $contact->companyName; } elseif (isset($contact->account) && $contact->account->id > 0) { try { $companyName = $contact->account->name; } catch (AccessDeniedSecurityException $e) { $companyName = $contact->companyName; } return $companyName; } else { return null; } }
/** * @depends testGetContactState */ public function testListLeadsStates() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); $leadStates = LeadsUtil::getLeadStateDataFromStartingStateLabelByLanguage(Yii::app()->language); $compareData = array(); foreach ($leadStates as $leadState) { $compareData[] = $this->getModelToApiDataUtilData($leadState); } $response = $this->createApiCallWithRelativeUrl('listLeadStates/', 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(count($compareData), count($response['data']['items'])); $this->assertEquals(count($compareData), $response['data']['totalCount']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals($compareData, $response['data']['items']); }
public function testCreateAccountForLeadConversionFromAccountPostData() { Yii::app()->user->userModel = User::getByUsername('super'); $super = Yii::app()->user->userModel; $contact = ContactTestHelper::createContactByNameForOwner('Contact3', $super); $controllerUtil = new ZurmoControllerUtil(); //Scenario #1 - Skip the account creation $accountPostData = array('AccountSkip' => true); $account = LeadsUtil::createAccountForLeadConversionFromAccountPostData($accountPostData, $contact, $controllerUtil); $this->assertNull($account); //Scenario #2 - Select an already existing account $account3 = AccountTestHelper::createAccountByNameForOwner('Account3', $super); $accountPostData = array('SelectAccount' => true, 'accountId' => $account3->id); $account = LeadsUtil::createAccountForLeadConversionFromAccountPostData($accountPostData, $contact, $controllerUtil); $this->assertEquals($account3->id, $account->id); //Scenario #3 - Create new account from POST data $accountPostData = array('CreateAccount' => true, 'name' => 'Account Created From Post', 'employees' => '5', 'website' => 'http://www.exa.com'); $account = LeadsUtil::createAccountForLeadConversionFromAccountPostData($accountPostData, $contact, $controllerUtil); $this->assertEquals('Account Created From Post', $account->name); $this->assertEquals(5, $account->employees); $this->assertEquals('http://www.exa.com', $account->website); }