/**
  * Given a contact state id, attempt to get and return a contact state object. If the id is invalid, then an
  * InvalidValueToSanitizeException will be thrown.
  * @param mixed $value
  * @return sanitized value
  * @throws InvalidValueToSanitizeException
  * @throws NotFoundException
  */
 public function sanitizeValue($value)
 {
     assert('$this->attributeName == null');
     if ($value == null) {
         return $value;
     }
     try {
         if ((int) $value <= 0) {
             $states = ContactState::getByName($value);
             if (count($states) > 1) {
                 throw new InvalidValueToSanitizeException(Zurmo::t('ContactsModule', 'Status specified is not unique and is invalid.'));
             } elseif (count($states) == 0) {
                 throw new NotFoundException();
             }
             $state = $states[0];
         } else {
             $state = ContactState::getById($value);
         }
         $startingState = ContactsUtil::getStartingState();
         if (!static::resolvesValidStateByOrder($state->order, $startingState->order)) {
             throw new InvalidValueToSanitizeException(Zurmo::t('ZurmoModule', 'Status specified is invalid.'));
         }
         return $state;
     } catch (NotFoundException $e) {
         throw new InvalidValueToSanitizeException(Zurmo::t('ContactsModule', 'Status specified does not exist.'));
     }
 }
 /**
  * Utilized to create or update model attribute values after a workflow's triggers are fired as true.
  * @param WorkflowActionProcessingModelAdapter $adapter
  * @param string $attribute
  * @throws NotSupportedException
  */
 public function resolveValueAndSetToModel(WorkflowActionProcessingModelAdapter $adapter, $attribute)
 {
     assert('is_string($attribute)');
     if ($this->type == WorkflowActionAttributeForm::TYPE_STATIC) {
         $adapter->getModel()->{$attribute} = ContactState::getById((int) $this->value);
         //todo: what if it doesn't exist anymore?
     } else {
         throw new NotSupportedException();
     }
 }
Пример #3
0
 public function testCreateAndGetContactState()
 {
     $state = new ContactState();
     $state->name = 'First State';
     $state->order = 0;
     $this->assertTrue($state->save());
     $id = $state->id;
     unset($state);
     $state = ContactState::getById($id);
     $this->assertEquals('First State', $state->name);
     $this->assertEquals(0, $state->order);
     $state->delete();
 }
 /**
  * Contact state is required.  If the value provided is null then the sanitizer will attempt use a default
  * value if provided.  If this is missing then a InvalidValueToSanitizeException will be thrown.
  * @param mixed $value
  * @return sanitized value
  * @throws InvalidValueToSanitizeException
  */
 public function sanitizeValue($value)
 {
     assert('$this->attributeName == null');
     assert('is_string($value) || $value == null || $value instanceof ContactState');
     $modelClassName = $this->modelClassName;
     $model = new $modelClassName(false);
     if ($value == null) {
         if (isset($this->mappingRuleData['defaultStateId']) && $this->mappingRuleData['defaultStateId'] != null) {
             try {
                 $state = ContactState::getById((int) $this->mappingRuleData['defaultStateId']);
             } catch (NotFoundException $e) {
                 throw new InvalidValueToSanitizeException(Zurmo::t('ContactsModule', 'The default status specified does not exist.'));
             }
             return $state;
         } else {
             throw new InvalidValueToSanitizeException(Zurmo::t('ContactsModule', 'The status is required.  Neither a value nor a default was specified.'));
         }
     }
     return $value;
 }
 public function testRenderHtmlContentLabelFromContactAndKeyword()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $contact = new Contact();
     $contact->firstName = 'johnny';
     $contact->lastName = 'five';
     $contact->owner = $super;
     $contact->state = ContactState::getById(5);
     $contact->primaryEmail = new Email();
     $contact->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($contact->save());
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $contact2 = new Contact();
     $contact2->firstName = 'johnny';
     $contact2->lastName = 'six';
     $contact2->owner = $super;
     $contact2->state = ContactState::getById(5);
     $contact2->primaryEmail = new Email();
     $contact2->primaryEmail->emailAddress = '*****@*****.**';
     $contact2->secondaryEmail = new Email();
     $contact2->secondaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($contact2->save());
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $contact3 = new Contact();
     $contact3->firstName = 'johnny';
     $contact3->lastName = 'seven';
     $contact3->owner = $super;
     $contact3->state = ContactState::getById(5);
     $this->assertTrue($contact3->save());
     $content = MultipleContactsForMeetingElement::renderHtmlContentLabelFromContactAndKeyword($contact, 'asdad');
     $this->assertEquals('johnny five&#160&#160<b>a@a.com</b>', $content);
     $content = MultipleContactsForMeetingElement::renderHtmlContentLabelFromContactAndKeyword($contact2, 'b@b');
     $this->assertEquals('johnny six&#160&#160<b>b@b.com</b>', $content);
     $content = MultipleContactsForMeetingElement::renderHtmlContentLabelFromContactAndKeyword($contact2, 'cc');
     $this->assertEquals('johnny six&#160&#160<b>a@a.com</b>', $content);
     $content = MultipleContactsForMeetingElement::renderHtmlContentLabelFromContactAndKeyword($contact3, 'cx');
     $this->assertEquals('johnny seven', $content);
 }
Пример #6
0
 /**
  * @return ContactState object
  */
 public static function getStartingState()
 {
     $metadata = ContactsModule::getMetadata();
     return ContactState::getById($metadata['global']['startingStateId']);
 }
Пример #7
0
 public function testContactsUtilSetStartingStateByOrder()
 {
     $startingStateId = ContactsUtil::getStartingStateId();
     $startingState = ContactState::getById($startingStateId);
     $startingState->delete();
     $this->assertEquals(6, count(ContactState::GetAll()));
     ContactsUtil::setStartingStateByOrder(2);
     $startingStateId = ContactsUtil::getStartingStateId();
     $states = ContactState::getAll('order');
     $this->assertEquals($states[1]->id, $startingStateId);
     $startingState = ContactState::getByName('Recycled');
     $this->assertEquals(1, count($startingState));
     $this->assertEquals($startingState[0]->id, $startingStateId);
 }
Пример #8
0
 /**
  * @depends testCreateStateValues
  */
 public function testAttributesToAccount()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $industries = array('Automotive', 'Adult Entertainment', 'Financial Services', 'Mercenaries & Armaments');
     $industryFieldData = CustomFieldData::getByName('Industries');
     $industryFieldData->serializedData = serialize($industries);
     $this->assertTrue($industryFieldData->save());
     $user = UserTestHelper::createBasicUser('Bobby');
     $contact = new Contact();
     $contact->owner = $user;
     $contact->title->value = 'Mr.';
     $contact->firstName = 'Super';
     $contact->lastName = 'Man';
     $contact->companyName = 'ABC Company';
     $stateIds = ContactsUtil::getContactStateDataKeyedById();
     foreach ($stateIds as $stateId => $notUsed) {
         $stateToUse = ContactState::getById($stateId);
         break;
     }
     $contact->state = $stateToUse;
     //grab first state.
     $contact->officePhone = '1234567890';
     $contact->officeFax = '1222222222';
     $contact->industry->value = $industries[1];
     $contact->website = 'http://www.something.com';
     $contact->primaryAddress->street1 = '129 Noodle Boulevard';
     $contact->primaryAddress->street2 = 'Apartment 6000A';
     $contact->primaryAddress->city = 'Noodleville';
     $contact->primaryAddress->postalCode = '23453';
     $contact->primaryAddress->country = 'The Good Old US of A';
     $contact->secondaryAddress->street1 = '25 de Agosto 2543';
     $contact->secondaryAddress->street2 = 'Local 3';
     $contact->secondaryAddress->city = 'Ciudad de Los Fideos';
     $contact->secondaryAddress->postalCode = '5123-4';
     $contact->secondaryAddress->country = 'Latinoland';
     $this->assertTrue($contact->save());
     $id = $contact->id;
     unset($contact);
     $contact = Contact::getById($id);
     $account = new Account();
     $account = LeadsUtil::attributesToAccount($contact, $account);
     $this->assertTrue($account->save());
     $id = $account->id;
     unset($account);
     $account = Account::getById($id);
     $this->assertEquals('ABC Company', $account->name);
     $this->assertEquals('1234567890', $account->officePhone);
     $this->assertEquals('1222222222', $account->officeFax);
     $this->assertEquals('http://www.something.com', $account->website);
     $this->assertEquals($industries[1], $account->industry->value);
     $this->assertEquals('super', $account->owner->username);
     $this->assertEquals('129 Noodle Boulevard', $account->billingAddress->street1);
     $this->assertEquals('Apartment 6000A', $account->billingAddress->street2);
     $this->assertEquals('Noodleville', $account->billingAddress->city);
     $this->assertEquals('23453', $account->billingAddress->postalCode);
     $this->assertEquals('The Good Old US of A', $account->billingAddress->country);
     $this->assertEquals('25 de Agosto 2543', $account->shippingAddress->street1);
     $this->assertEquals('Local 3', $account->shippingAddress->street2);
     $this->assertEquals('Ciudad de Los Fideos', $account->shippingAddress->city);
     $this->assertEquals('5123-4', $account->shippingAddress->postalCode);
     $this->assertEquals('Latinoland', $account->shippingAddress->country);
 }