From 726a3efe800bead97eaf7b71d78272dbb3dc3354 Mon Sep 17 00:00:00 2001 From: Cesar Velez Date: Mon, 13 Nov 2017 18:25:05 -0500 Subject: [PATCH] LP#1732275: add open-ils.actor.user.itemsout.notices api Add a method to Actor.pm to count completed action trigger events for a given circ and return the latest notice date. Uses the json_query for performance. Signed-off-by: Cesar Velez Signed-off-by: Galen Charlton Signed-off-by: Kathy Lussier --- .../perlmods/lib/OpenILS/Application/Actor.pm | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index ef90fdb555..84b328e47b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -3632,7 +3632,66 @@ sub copy_events { } +__PACKAGE__->register_method ( + method => 'get_itemsout_notices', + api_name => 'open-ils.actor.user.itemsout.notices', + stream => 1, + argc => 3 +); + +sub get_itemsout_notices{ + my( $self, $conn, $auth, $circId, $patronId) = @_; + + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + + my $requestorId = $e->requestor->id; + + if( $patronId ne $requestorId ){ + my $user = $e->retrieve_actor_user($requestorId) or return $e->event; + return $e->event unless $e->allowed('VIEW_CIRCULATIONS', $user->home_ou); + } + + #my $ses = OpenSRF::AppSession->create('open-ils.trigger'); + #my $req = $ses->request('open-ils.trigger.events_by_target', + # 'circ', {target => [$circId], event=> {state=>'complete'}}); + # ^ Above removed in favor of faster json_query. + # + # SQL: + # select complete_time + # from action_trigger.event atev + # JOIN action_trigger.event_definition def ON (def.id = atev.event_def) + # JOIN action_trigger.hook athook ON (athook.key = def.hook) + # where hook = 'checkout.due' AND state = 'complete' and target = ; + # + + my $query = { + select => { atev => ["complete_time"] }, + from => { + atev => { + atevdef => { field => "id",fkey => "event_def", join => { ath => { field => "key", fkey => "hook" }} } + } + }, + where => {"+ath" => { key => "checkout.due" },"+atevdef" => { active => 't' },"+atev" => { target => $circId, state => 'complete' }} + }; + + my %resblob = ( numNotices => 0, lastDt => undef ); + my $res = $e->json_query($query); + for my $ndate (@$res) { + $resblob{numNotices}++; + if( !defined $resblob{lastDt}){ + $resblob{lastDt} = $$ndate{complete_time}; + } + + if ($resblob{lastDt} lt $$ndate{complete_time}){ + $resblob{lastDt} = $$ndate{complete_time}; + } + } + + $conn->respond(\%resblob); + return undef; +} __PACKAGE__->register_method ( method => 'update_events', -- 2.43.2