current_shelf_lib : ML misc holds list sorting hold-current-shelf-lib-scratch
authorBill Erickson <berick@esilibrary.com>
Wed, 28 Dec 2011 20:44:36 +0000 (15:44 -0500)
committerBill Erickson <berick@esilibrary.com>
Wed, 28 Dec 2011 21:09:41 +0000 (16:09 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm

index a5b76f9..8378342 100644 (file)
@@ -529,7 +529,7 @@ sub retrieve_holds {
 
     } else {
 
-        # order non-cancelled holds by ready-for-pickup, then active, followed by suspended
+        # order non-cancelled holds by shelf_time, then active, followed by suspended
         $holds_query->{order_by} = {ahr => ['shelf_time', 'frozen', 'request_time']};
         $holds_query->{where}->{cancel_time} = undef;
     }
@@ -537,6 +537,31 @@ sub retrieve_holds {
     my $hold_ids = $e->json_query($holds_query);
     $hold_ids = [ map { $_->{id} } @$hold_ids ];
 
+    # do a follow up sort to determine which holds
+    # are in fact on the pickup lib's holds shelf.
+    # XXX not finding any way to compare column values in the 
+    # order_by, which would make this much better/faster/cleaner
+    if($self->api_name !~ /canceled/) {
+
+        # find the available holds
+        my @avail_ids = map {$_->{id}} 
+            @{$e->json_query({
+                select => {ahr => ['id']},
+                from => 'ahr',
+                where => {
+                    id => $hold_ids,
+                    current_shelf_lib => {'=' => {'+ahr' => 'pickup_lib'}}
+                }
+            })
+        };
+        # find the non-available holds
+        my @non_avail;
+        for my $id (@$hold_ids) {
+            push(@non_avail, $id) unless grep { $_ == $id } @avail_ids;
+        }
+        $hold_ids = [@avail_ids, @non_avail];
+    }
+
     return $hold_ids if $self->api_name =~ /id_list/;
 
     my @holds;