TPac; sort items out list by due date, oldest first
authorBill Erickson <berick@esilibrary.com>
Wed, 2 Nov 2011 19:45:06 +0000 (15:45 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 4 Nov 2011 21:47:41 +0000 (17:47 -0400)
Sort items most in need of return (i.e. oldest due date) to top.  This
is done by replacing the call to "open-ils.actor.user.checked_out",
which does a lot more than we need, in a way that does not support
sorting/paging, with a simple json_query.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm

index c84bed4..f14a200 100644 (file)
@@ -767,18 +767,27 @@ sub fetch_user_circs {
 
     } else {
 
-        my $circ_data = $U->simplereq(
-            'open-ils.actor', 
-            'open-ils.actor.user.checked_out',
-            $e->authtoken, 
-            $e->requestor->id
-        );
+        my $query = {
+            select => {circ => ['id']},
+            from => 'circ',
+            where => {
+                '+circ' => {
+                    usr => $e->requestor->id,
+                    checkin_time => undef,
+                    '-or' => [
+                        {stop_fines => undef},
+                        {stop_fines => {'not in' => ['LOST','CLAIMSRETURNED','LONGOVERDUE']}}
+                    ],
+                }
+            },
+            order_by => {circ => ['due_date']}
+        };
 
-        @circ_ids =  ( @{$circ_data->{overdue}}, @{$circ_data->{out}} );
+        $query->{limit} = $limit if $limit;
+        $query->{offset} = $offset if $offset;
 
-        if($limit or $offset) {
-            @circ_ids = grep { defined $_ } @circ_ids[0..($offset + $limit - 1)];
-        }
+        my $ids = $e->json_query($query);
+        @circ_ids = map {$_->{id}} @$ids;
     }
 
     return [] unless @circ_ids;