Filter area and city searches.
[readifood.git] / lib / order.php
index 4b1c42e..d48f214 100644 (file)
       return;
     }
 
+    $candidates = array();
+    foreach ($areas as $area) {
+      if (! count(get_area_contacts($area->getId()))) continue;
+      $candidates[] = $area;
+    }
+    if (! count($candidates)) return;
+
     echo "<p>Show orders in area\n";
     echo "<select name=\"area_id\">\n";
-    foreach ($areas as $area) {
+    foreach ($candidates as $area) {
       option("area_id", $area->getId(), get_area_displayname($area));
     }
     echo "</select>\n";
       return;
     }
 
+    $candidates = array();
+    foreach ($cities as $city) {
+      if (! count(get_city_contacts($city->getId()))) continue;
+      $candidates[] = $city;
+    }
+    if (! count($candidates)) return;
+
     echo "<p>Show orders in city\n";
     echo "<select name=\"city_id\">\n";
-    foreach ($cities as $city) {
+    foreach ($candidates as $city) {
       option("city_id", $city->getId(), get_city_displayname($city), $city_id);
     }
     echo "</select>\n";
     global $states, $parcel_sizes, $parcel_contents;
 
     if ($order) {
-      $q = new OrderStateQuery;
-      $order_state = $q->filterByOrderId($order->getId())->orderByUpdated('desc')->limit(1)->findOne();
+      $order_state = get_order_state($order);
       if ($order_state) {
         $state = $order_state->getState();
         $driver_id = $order_state->getDriverId();
     }
     else $order = new Order;
 
-
     /* Date. */
     echo "<tr>\n";
     echo "  <td>Delivery</td>\n";
       if ($driver_id) $driver = get_contact_by_id($driver_id);
       else $driver = null;
 
-      /* XXX */
-      $state = $order_state->getState();
-      for ($i = 0; $i < count($states); $i++) {
-        if ((1 << $i) == $state) {
-          $state = $states[$i];
-          break;
-        }
-      }
-      #$state = $states[$order_state->getState()];
-      echo "<strong>$username</strong> changed order to state <strong>$state</strong>";
+      echo "<strong>$username</strong> changed order to state <strong>" . get_order_state_string($order_state) . "</strong>";
       if ($driver) echo " for driver " . $driver->getDisplayname();
       echo " on $date.<br>\n";
     }