From 8df2cecbda7595eb24d7f8cde6984a6285b43ef6 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 10 Nov 2008 21:35:36 +0000 Subject: [PATCH] added method to return basic hold queue information git-svn-id: svn://svn.open-ils.org/ILS/trunk@11120 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Circ/Holds.pm | 56 ++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm index 6ec2104ccf..813cc6d4bf 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm @@ -654,10 +654,58 @@ sub _hold_status { } -#sub find_local_hold { -# my( $class, $session, $copy, $user ) = @_; -# return $class->find_nearest_permitted_hold($session, $copy, $user); -#} + +__PACKAGE__->register_method( + method => "retrieve_hold_queue_stats", + api_name => "open-ils.circ.hold.queue_stats.retrieve", + signature => { + desc => q/ + Returns object with total_holds count, queue_position, and potential_copies count + / + } +); + +sub retrieve_hold_queue_stats { + my($self, $conn, $auth, $hold_id) = @_; + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + my $hold = $e->retrieve_action_hold_request($hold_id) or return $e->event; + if($e->requestor->id != $hold->usr) { + return $e->event unless $e->allowed('VIEW_HOLD'); + } + return retrieve_hold_queue_status_impl($e, $hold); +} + +sub retrieve_hold_queue_status_impl { + my $e = shift; + my $hold = shift; + + my $hold_ids = $e->search_action_hold_request( + [ + { target => $hold->target, + hold_type => $hold->hold_type, + cancel_time => undef, + fulfillment_time => undef + }, + {order_by => {ahr => 'request_time asc'}} + ], + {idlist => 1} + ); + + my $pos = 0; + for my $hid (@$hold_ids) { + $pos++; + last if $hid == $hold->id; + } + + my $potentials = $e->search_action_hold_copy_map({hold => $hold->id}, {idlist => 1}); + + return { + total_holds => scalar(@$hold_ids), + queue_position => $pos, + potential_copies => scalar(@$potentials) + }; +} sub fetch_open_hold_by_current_copy { -- 2.11.0