/**
  * Gets matched models
  * @param $value
  * @param null|int $pageSize
  * @return array
  */
 protected function getMatchedModels($value, $pageSize)
 {
     $matchedModels = array();
     $penultimateModelClassName = $this->penultimateModelClassName;
     if ($penultimateModelClassName == 'Account') {
         $matchedModels = AccountSearch::getAccountsByAnyEmailAddress($value, $pageSize);
     } elseif ($penultimateModelClassName == 'Contact') {
         $matchedModels = ContactSearch::getContactsByAnyEmailAddress($value, $pageSize);
     }
     return $matchedModels;
 }
 public function testGetAccountsByAnyEmailAddress()
 {
     $data = AccountSearch::getAccountsByAnyEmailAddress('*****@*****.**', 5);
     $this->assertEquals(0, count($data));
     //search by primaryEmail
     $data = AccountSearch::getAccountsByAnyEmailAddress('*****@*****.**', 5);
     $this->assertEquals(1, count($data));
     $this->assertEquals('Zurmo', $data[0]->name);
     //search by secondaryEmail
     $data = AccountSearch::getAccountsByAnyEmailAddress('*****@*****.**', 5);
     $this->assertEquals(1, count($data));
     $this->assertEquals('Roger', $data[0]->name);
 }
 /**
  * Get Contact or Account or User, based on email address
  * @param string $emailAddress
  * @param boolean $userCanAccessContacts
  * @param boolean $userCanAccessLeads
  * @param boolean $userCanAccessAccounts
  * @return Contact || Account || User || NULL
  */
 public static function resolvePersonOrAccountByEmailAddress($emailAddress, $userCanAccessContacts = false, $userCanAccessLeads = false, $userCanAccessAccounts = false)
 {
     assert('is_string($emailAddress)');
     assert('is_bool($userCanAccessContacts)');
     assert('is_bool($userCanAccessLeads)');
     assert('is_bool($userCanAccessAccounts)');
     $personOrAccount = null;
     $contactsOrLeads = array();
     if ($userCanAccessContacts || $userCanAccessLeads) {
         $stateMetadataAdapterClassName = LeadsStateMetadataAdapter::resolveStateMetadataAdapterClassNameByAccess($userCanAccessContacts, $userCanAccessLeads);
         $contactsOrLeads = ContactSearch::getContactsByAnyEmailAddress($emailAddress, null, $stateMetadataAdapterClassName);
     }
     if (!empty($contactsOrLeads)) {
         $personOrAccount = $contactsOrLeads[0];
     } else {
         $accounts = array();
         // Check if email belongs to account
         if ($userCanAccessAccounts) {
             $accounts = AccountSearch::getAccountsByAnyEmailAddress($emailAddress);
         }
         if (count($accounts)) {
             $personOrAccount = $accounts[0];
         } else {
             $users = UserSearch::getUsersByEmailAddress($emailAddress);
             if (count($users)) {
                 $personOrAccount = $users[0];
             }
         }
     }
     return $personOrAccount;
 }
 public function testGetAccountsByPartialName()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $data = AccountSearch::getAccountsByPartialName('zurmo');
     $this->assertEquals(1, count($data));
     $this->assertEquals('Zurmo', $data[0]->name);
     $data = AccountSearch::getAccountsByPartialName('sonite');
     $this->assertEquals(1, count($data));
     $this->assertEquals('Samsonite', $data[0]->name);
     $data = AccountSearch::getAccountsByPartialName('u');
     $this->assertEquals(3, count($data));
 }