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);
 }
 /**
  * Given a partial name or e-mail address, search for all contacts or users regardless of contact state unless
  * the current user has security restrictions on some states. If the adapter resolver returns false, then the
  * user does not have access to the Leads or Contacts module.
  * JSON encode the resulting array of contacts.
  */
 public function actionAutoCompleteAllContactsOrUsersForMultiSelectAutoComplete($term, $autoCompleteOptions = null)
 {
     $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('autoCompleteListPageSize', get_class($this->getModule()));
     $adapterName = ContactsUtil::resolveContactStateAdapterByModulesUserHasAccessTo('LeadsModule', 'ContactsModule', Yii::app()->user->userModel);
     if ($adapterName === false) {
         $messageView = new AccessFailureView();
         $view = new AccessFailurePageView($messageView);
         echo $view->render();
         Yii::app()->end(0, false);
     }
     $contacts = ContactSearch::getContactsByPartialFullNameOrAnyEmailAddress($term, $pageSize, $adapterName, null, $autoCompleteOptions);
     $autoCompleteResults = array();
     foreach ($contacts as $contact) {
         $autoCompleteResults[] = array('id' => Meeting::CONTACT_ATTENDEE_PREFIX . $contact->id, 'name' => MultipleContactsForMeetingElement::renderHtmlContentLabelFromContactAndKeyword($contact, $term));
     }
     $users = UserSearch::getUsersByPartialFullNameOrAnyEmailAddress($term, $pageSize, null, null, $autoCompleteOptions);
     foreach ($users as $user) {
         $autoCompleteResults[] = array('id' => Meeting::USER_ATTENDEE_PREFIX . $user->id, 'name' => MultipleContactsForMeetingElement::renderHtmlContentLabelFromUserAndKeyword($user, $term));
     }
     echo CJSON::encode($autoCompleteResults);
 }
 public function actionAutoCompleteGroupsAndUsers($term)
 {
     $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('autoCompleteListPageSize', get_class($this->getModule()));
     $groups = ModelAutoCompleteUtil::getByPartialName('Group', $term, $pageSize);
     $users = UserSearch::getUsersByPartialFullNameOrAnyEmailAddress($term, $pageSize, null);
     $autoCompleteResults = array();
     foreach ($groups as $group) {
         $autoCompleteResults[] = array('id' => PushDashboardUtil::GROUP_PREFIX . $group['id'], 'name' => $group['value']);
     }
     foreach ($users as $user) {
         $autoCompleteResults[] = array('id' => PushDashboardUtil::USER_PREFIX . $user->id, 'name' => MultipleContactsForMeetingElement::renderHtmlContentLabelFromUserAndKeyword($user, $term));
     }
     echo CJSON::encode($autoCompleteResults);
 }