Extend contact search to address.
authorIain Patterson <me@iain.cx>
Sun, 16 Jun 2013 11:49:34 +0000 (07:49 -0400)
committerIain Patterson <me@iain.cx>
Sun, 16 Jun 2013 11:49:34 +0000 (07:49 -0400)
Find contacts whose address matches the search string as well as those
whose name matches.

lib/contact.php

index 25aab58..56327de 100644 (file)
     }
     else echo "none";
     echo "</p>\n";
+
+    $address_ids = array();
+    $q = new AddressQuery;
+    $addresses = $q->filterByLine("%$search%")->find();
+    foreach ($addresses as $address) $address_ids[] = $address->getId();
+    $q = new AddressQuery;
+    $addresses = $q->filterByPostcode("%$search%")->find();
+    foreach ($addresses as $address) $address_ids[] = $address->getId();
+
+    $q = new ContactQuery;
+    $contacts = $q->filterByAddressId($address_ids)->find();
+    echo "<p>Contacts in address '" . htmlspecialchars($search) . "':";
+    if (count($contacts)) {
+      foreach ($contacts as $contact) show_contact_summary($contact);
+    }
+    else echo "none";
+    echo "</p>\n";
   }
 
   function show_city_contacts($offset, $per_page, $city_name, $city_id = null) {