Exemplo n.º 1
0
 public function searchContacts($query)
 {
     $query = trim($query);
     $this->view->query = $query;
     // split into two and look for an exact match
     $names = split(" ", $query);
     if (count($names) == 2) {
         // see if there's someone with the same firstname/surname
         $contact = $this->clientService->getContactByFields(array('firstname' => $names[0], 'lastname' => $names[1]));
         if ($contact != null) {
             $this->redirect('contact', 'edit', array('id' => $contact->id));
             return;
         }
     }
     // Otherwise, just look for contacts with a firstname or lastname like the entered name
     $this->view->contacts = $this->clientService->getContactsByNames($names);
     if ($this->_getParam('_ajax')) {
         $this->renderRawView('search/contacts.php');
     } else {
         $this->renderView('search/contacts.php');
     }
 }