Exemplo n.º 1
0
 /**
  * Does different searches depending on the indexes of the $query
  *
  * @query['address'] Will do a search in CRM and a search for addresses in Master Address
  * @query['street'] Will do a search in CRM and a search for streets in Master Address
  * @query['text'] Will only do a search in CRM
  *
  * Addresses will be return as $array['location text'] = $flag
  * where $flag is true if returned by AddressService
  *
  * @param array $query
  * @return array
  */
 public static function search($query)
 {
     $results = array();
     $crm_query = '';
     if (isset($query['address']) && $query['address']) {
         $crm_query = $query['address'];
     } elseif (isset($query['text']) && $query['text']) {
         $crm_query = $query['text'];
     }
     if ($crm_query) {
         $zend_db = Database::getConnection();
         $sql = "select location, addressId, city,\n\t\t\t\t\t'database' as source,\n\t\t\t\t\tcount(*) as ticketCount\n\t\t\t\t\tfrom tickets where location like ?\n\t\t\t\t\tgroup by location, addressId, city";
         $q = $zend_db->query($sql)->execute(["{$crm_query}%"]);
         foreach ($q as $row) {
             $results[$row['location']] = $row;
         }
     }
     if (isset($query['address']) && $query['address']) {
         foreach (AddressService::searchAddresses($query['address']) as $location => $data) {
             if (!isset($results[$location])) {
                 $results[$location] = $data;
             } else {
                 $results[$location] = array_merge($results[$location], $data);
             }
             $results[$location]['source'] = 'Master Address';
         }
     } elseif (isset($query['street']) && $query['street']) {
         foreach (AddressService::searchStreets($query['street']) as $location => $street_id) {
             $results[$location]['addressId'] = $street_id;
             $results[$location]['source'] = 'Master Address';
         }
     }
     return $results;
 }
 /**
  * @param REQUEST ticket_id
  * @param REQUEST location
  */
 public function changeLocation()
 {
     $ticket = $this->loadTicket($_REQUEST['ticket_id']);
     // Once the user has chosen a location, they'll pass it in here
     if (isset($_REQUEST['location']) && $_REQUEST['location']) {
         $ticket->clearAddressServiceData();
         $ticket->setLocation($_REQUEST['location']);
         $ticket->setAddressServiceData(AddressService::getLocationData($ticket->getLocation()));
         try {
             $ticket->save();
             $this->redirectToTicketView($ticket);
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     }
     $_REQUEST['return_url'] = new Url($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
     $this->template->setFilename('tickets');
     $this->template->blocks['ticket-panel'][] = new Block('locations/findLocationForm.inc', array('includeExternalResults' => true));
     $this->addStandardInfoBlocks($ticket);
 }
 public function testSearchAddresses()
 {
     $result = AddressService::searchAddresses('Somersbe Pl');
     $this->assertEquals(40, count($result));
 }
Exemplo n.º 4
0
 /**
  * Populates available fields from the given array
  *
  * @param array $post
  */
 public function handleUpdate($post)
 {
     // Set all the location information using any fields the user posted
     $fields = array('category_id', 'client_id', 'assignedPerson_id', 'location', 'latitude', 'longitude', 'city', 'state', 'zip');
     foreach ($fields as $field) {
         if (isset($post[$field])) {
             $set = 'set' . ucfirst($field);
             $this->{$set}($post[$field]);
         }
     }
     // If they gave us an address, and we don't have any additional info,
     // try and get the data from Master Address
     if ($this->getLocation() && (!$this->getLatitude() || !$this->getLongitude() || !$this->getCity() || !$this->getState() || !$this->getZip())) {
         $data = AddressService::getLocationData($this->getLocation());
         if ($data) {
             $this->setAddressServiceData($data);
         }
     }
 }