From: Iain Patterson Date: Mon, 22 Apr 2013 20:39:16 +0000 (-0400) Subject: Added get_order_ids_by_state(). X-Git-Tag: 2013-05-13~33 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=48175505d7f95be28b778fbca3826e34ba505cde;p=readifood.git Added get_order_ids_by_state(). Function to find orders in a given state. --- diff --git a/lib/functions.php b/lib/functions.php index 801ed78..2f32a22 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -175,6 +175,16 @@ 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); diff --git a/lib/order.php b/lib/order.php index 9c9e1c9..69026bf 100644 --- a/lib/order.php +++ b/lib/order.php @@ -40,14 +40,7 @@ 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);