circ history sorting newest to oldest, got paging working, but could use some work..
authorberick <berick@esilibrary.com>
Wed, 6 Apr 2011 21:52:10 +0000 (17:52 -0400)
committerberick <berick@esilibrary.com>
Wed, 6 Apr 2011 21:52:10 +0000 (17:52 -0400)
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm

index e7a961d..552e5c5 100644 (file)
@@ -36,7 +36,7 @@ sub load_myopac_prefs_notify {
     $user_prefs = $self->update_optin_prefs($user_prefs)
         if $self->cgi->request_method eq 'POST';
 
-    $self->ctx->{opt_in_settings} = $user_prefs;
+    $self->ctx->{opt_in_settings} = $user_prefs; 
 
     return Apache2::Const::OK;
 }
@@ -507,15 +507,27 @@ sub load_myopac_circ_history {
     my $e = $self->editor;
     my $ctx = $self->ctx;
     my $limit = $self->cgi->param('limit');
-    my $offset = $self->cgi->param('offset');
+    my $offset = $self->cgi->param('offset') || 0;
 
     my $circs = $e->json_query({
         from => ['action.usr_visible_circs', $e->requestor->id],
-        limit => $limit || 25,
-        offset => $offset || 0
+        #limit => $limit || 25,
+        #offset => $offset || 0,
     });
 
-    $ctx->{circs} = $self->fetch_user_circs(1, [map { $_->{id} } @$circs], $limit, $offset);
+    # XXX: order-by in the json_query above appears to do nothing, so in-query 
+    # paging is not reallly an option.  do the sorting/paging here
+
+    # sort newest to oldest
+    $circs = [ sort { $b->{xact_start} cmp $a->{xact_start} } @$circs ];
+    my @ids = map { $_->{id} } @$circs;
+
+    # find the selected page and trim cruft
+    @ids = @ids[$offset..($offset + $limit - 1)] if $limit;
+    @ids = grep { defined $_ } @ids;
+
+    $ctx->{circs} = $self->fetch_user_circs(1, \@ids, $limit, $offset);
+    #$ctx->{circs} = $self->fetch_user_circs(1, [map { $_->{id} } @$circs], $limit, $offset);
 
     return Apache2::Const::OK;
 }