From 5c065fb198836354a4ad38778064b208f9e38b41 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 28 Dec 2011 15:44:36 -0500 Subject: [PATCH] current_shelf_lib : ML misc holds list sorting Signed-off-by: Bill Erickson --- .../perlmods/lib/OpenILS/Application/Circ/Holds.pm | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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..8378342883 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm @@ -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; -- 2.11.0