From: Bill Erickson <berick@esilibrary.com>
Date: Wed, 28 Dec 2011 20:44:36 +0000 (-0500)
Subject: Use hold current shelf lib to determine availability : opac sorting
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d2f41ba6829aad91367cb5e47a5825ffcb7ee2df;p=evergreen%2Fmasslnc.git

Use hold current shelf lib to determine availability : opac sorting

The availability of a hold can now be determined by
hold.current_shelf_lib == hold.pickup_lib.

This change uses the new hold availability test to sort available
holds to front/top of a patron's holds list (for the OPAC).

Affects open-ils.circ.holds[.canceled|id_list].retrieve

Signed-off-by: Bill Erickson <berick@esilibrary.com>
---

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
index a5b76f9f0f..38f269fe95 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
@@ -530,7 +530,17 @@ sub retrieve_holds {
     } else {
 
         # order non-cancelled holds by ready-for-pickup, then active, followed by suspended
-        $holds_query->{order_by} = {ahr => ['shelf_time', 'frozen', 'request_time']};
+        # "compare" sorts false values to the front.  testing pickup_lib != current_shelf_lib
+        # will sort by pl = csl > pl != csl > followed by csl is null;
+        $holds_query->{order_by} = [
+            {   class => 'ahr', 
+                field => 'pickup_lib', 
+                compare => {'!='  => {'+ahr' => 'current_shelf_lib'}}},
+            {class => 'ahr', field => 'shelf_time'},
+            {class => 'ahr', field => 'frozen'},
+            {class => 'ahr', field => 'request_time'}
+
+        ];
         $holds_query->{where}->{cancel_time} = undef;
     }