Use get_order_state*() functions.
authorIain Patterson <me@iain.cx>
Mon, 13 May 2013 09:58:49 +0000 (05:58 -0400)
committerIain Patterson <me@iain.cx>
Mon, 13 May 2013 12:48:08 +0000 (08:48 -0400)
Use the new functions get_order_state() and get_order_state_string()
where we were previously accessing the state directly.

lib/order.php

index 4b1c42e..2eae9e0 100644 (file)
     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";
     }