Added get_order_ids_by_state().
authorIain Patterson <me@iain.cx>
Mon, 22 Apr 2013 20:39:16 +0000 (16:39 -0400)
committerIain Patterson <me@iain.cx>
Mon, 22 Apr 2013 20:39:16 +0000 (16:39 -0400)
Function to find orders in a given state.

lib/functions.php
lib/order.php

index 801ed78..2f32a22 100644 (file)
     return $order;
   }
 
+  function get_order_ids_by_state($state_mask) {
+    $order_ids = array();
+    $dbh = Propel::getConnection();
+    $sth = $dbh->prepare("select * from OrderState o where updated=(select max(updated) from OrderState where order_id=o.order_id) and state & $state_mask");
+    $sth->execute();
+    $order_states = OrderStatePeer::populateObjects($sth);
+    foreach ($order_states as $order_state) $order_ids[] = $order_state->getOrderId();
+    return $order_ids;
+  }
+
   function get_user_by_contact_id($id, $verbose = true) {
     $q = new UserQuery;
     $user = $q->findOneByContactId($id);
index 9c9e1c9..69026bf 100644 (file)
 
   function show_orders($offset, $per_page, $requester_ids = null, $beneficiary_ids = null, $state_mask = null) {
     /* XXX: Use Propel methods. */
-    if (isset($state_mask)) {
-      $order_ids = array();
-      $dbh = Propel::getConnection();
-      $sth = $dbh->prepare("select * from OrderState o where updated=(select max(updated) from OrderState where order_id=o.order_id) and state & $state_mask");
-      $sth->execute();
-      $order_states = OrderStatePeer::populateObjects($sth);
-      foreach ($order_states as $order_state) $order_ids[] = $order_state->getOrderId();
-    }
+    if (isset($state_mask)) $order_ids = get_order_ids_by_state($state_mask);
     $q = new OrderQuery;
     if (isset($requester_ids)) $q->filterByRequesterId($requester_ids);
     if (isset($beneficiary_ids)) $q->filterByBeneficiaryId($beneficiary_ids);