Split get_contact_orders().
authorIain Patterson <me@iain.cx>
Mon, 13 May 2013 08:50:21 +0000 (04:50 -0400)
committerIain Patterson <me@iain.cx>
Mon, 13 May 2013 12:48:07 +0000 (08:48 -0400)
Added get_beneficiary_orders() and get_requester_orders() to show orders
for which a given Contact is a beneficiary or requester.
Reworked get_contact_orders() to show orders of either type.

lib/functions.php

index ecaf2ad..8db2720 100644 (file)
     return $order_ids;
   }
 
-  function get_contact_orders($contact, $state_mask = null) {
+  function get_beneficiary_orders($contact, $state_mask = null) {
     $q = new OrderQuery;
     $q->filterByBeneficiaryId($contact->getId());
     if ($state_mask) $q->filterById(get_order_ids_by_state($state_mask));
     return $q->orderByDate()->find();
   }
 
+  function get_requester_orders($contact, $state_mask = null) {
+    $q = new OrderQuery;
+    $q->filterByRequesterId($contact->getId());
+    if ($state_mask) $q->filterById(get_order_ids_by_state($state_mask));
+    return $q->orderByDate()->find();
+  }
+
+  function get_contact_orders($contact, $state_mask = null) {
+    $q = new OrderQuery;
+    $q->filterByBeneficiaryId($contact->getId())->_or()->filterByRequesterId($contact->getId());
+    if ($state_mask) $q->filterById(get_order_ids_by_state($state_mask));
+    return $q->orderByDate()->find();
+  }
+
   function get_user_by_contact_id($id, $verbose = true) {
     $q = new UserQuery;
     $user = $q->findOneByContactId($id);