From 2e9379f49dafc701e7cacc69ded28187ca662de4 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 19 Nov 2009 16:25:20 +0000 Subject: [PATCH] created general purpose 'a copy for a theoretical hold is available at shelving location X for org Y'. can be used by the OPAC to nudge (or force) users toward just grabbing the copy instead of placing a hold git-svn-id: svn://svn.open-ils.org/ILS/trunk@14977 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Circ/Holds.pm | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm index 3e97df2b15..92ba6e5278 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm @@ -2158,4 +2158,84 @@ sub usr_hold_summary { } + +__PACKAGE__->register_method( + method => 'hold_has_copy_at', + api_name => 'open-ils.circ.hold.has_copy_at', + signature => q/ + Returns the ID of the found copy and name of the shelving location if there is + an available copy at the specified org unit. Returns empty hash otherwise. + / +); + +sub hold_has_copy_at { + my($self, $conn, $auth, $args) = @_; + + my $e = new_editor(authtoken=>$auth); + $e->checkauth or return $e->event; + + my $hold_type = $$args{hold_type}; + my $hold_target = $$args{hold_target}; + my $org_unit = $$args{org_unit}; + + my $query = { + select => {acp => ['id'], acpl => ['name']}, + from => { + acp => { + acpl => {field => 'id', filter => { holdable => 't'}, fkey => 'location'}, + ccs => {field => 'id', filter => { holdable => 't'}, fkey => 'status'} + } + }, + where => {'+acp' => { circulate => 't', deleted => 'f', holdable => 't', circ_lib => $org_unit}}, + limit => 1 + }; + + if($hold_type eq 'C') { + + $query->{where}->{'+acp'}->{id} = $hold_target; + + } elsif($hold_type eq 'V') { + + $query->{where}->{'+acp'}->{call_number} = $hold_target; + + } elsif($hold_type eq 'T') { + + $query->{from}->{acp}->{acn} = { + field => 'id', + fkey => 'call_number', + 'join' => { + bre => { + field => 'id', + filter => {id => $hold_target}, + fkey => 'record' + } + } + }; + + } else { + + $query->{from}->{acp}->{acn} = { + field => 'id', + fkey => 'call_number', + join => { + bre => { + field => 'id', + fkey => 'record', + join => { + mmrsm => { + field => 'source', + fkey => 'id', + filter => {metarecord => $hold_target}, + } + } + } + } + }; + } + + my $res = $e->json_query($query)->[0] or return {}; + return {copy => $res->{id}, location => $res->{name}} if $res; +} + + 1; -- 2.43.2