Merge branch 'master' of git.evergreen-ils.org:Evergreen into template-toolkit-opac
[evergreen-equinox.git] / Open-ILS / src / perlmods / lib / OpenILS / Application / Actor.pm
index 8d6659e..1502129 100644 (file)
@@ -1815,39 +1815,31 @@ __PACKAGE__->register_method(
 );
        
 sub hold_request_count {
-       my( $self, $client, $login_session, $userid ) = @_;
-
-       my( $user_obj, $target, $evt ) = $apputils->checkses_requestor(
-               $login_session, $userid, 'VIEW_HOLD' );
-       return $evt if $evt;
-       
-
-       my $holds = $apputils->simple_scalar_request(
-                       "open-ils.cstore",
-                       "open-ils.cstore.direct.action.hold_request.search.atomic",
-                       { 
-                               usr => $userid,
-                               fulfillment_time => {"=" => undef },
-                               cancel_time => undef,
-                       }
-       );
+       my( $self, $client, $authtoken, $user_id ) = @_;
+    my $e = new_editor(authtoken => $authtoken);
+    return $e->event unless $e->checkauth;
 
-       my @ready;
-       for my $h (@$holds) {
-               next unless $h->capture_time and $h->current_copy;
+    $user_id = $e->requestor->id unless defined $user_id;
 
-               my $copy = $apputils->simple_scalar_request(
-                       "open-ils.cstore",
-                       "open-ils.cstore.direct.asset.copy.retrieve",
-                       $h->current_copy
-               );
+    if($e->requestor->id ne $user_id) {
+        my $user = $e->retrieve_actor_user($user_id);
+        return $e->event unless $e->allowed('VIEW_HOLD', $user->home_ou);
+    }
 
-               if ($copy and $copy->status == 8) {
-                       push @ready, $h;
-               }
-       }
+    my $holds = $e->json_query({
+        select => {ahr => ['shelf_time']},
+        from => 'ahr',
+        where => {
+            usr => $user_id,
+            fulfillment_time => {"=" => undef },
+            cancel_time => undef,
+        }
+    });
 
-       return { total => scalar(@$holds), ready => scalar(@ready) };
+       return { 
+        total => scalar(@$holds), 
+        ready => scalar(grep { $_->{shelf_time} } @$holds) 
+    };
 }
 
 __PACKAGE__->register_method(