LP#1527342 TPAC display
authorBill Erickson <berickxx@gmail.com>
Mon, 21 Dec 2015 16:19:19 +0000 (11:19 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 21 Dec 2015 16:19:19 +0000 (11:19 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm

index 30e0756..4444f58 100644 (file)
@@ -1526,38 +1526,62 @@ sub load_myopac_circ_history {
     $ctx->{circ_history_limit} = $limit;
     $ctx->{circ_history_offset} = $offset;
 
-    my $circ_ids;
-    if ($self->cgi->param('sort') ne "") {             # Defer limitation to circ_history.tt2
-       $circ_ids = $e->json_query({
-        select => {
-            au => [{
-                column => 'id', 
-                transform => 'action.usr_visible_circs', 
-                result_field => 'id'
-            }]
+    # Defer limitation to circ_history.tt2 when sorting
+    if ($self->cgi->param('sort')) {
+        $limit = undef;
+        $offset = undef;
+    }
+
+    $ctx->{circs} = $self->fetch_user_circ_history(1, $limit, $offset);
+    return Apache2::Const::OK;
+}
+
+# if 'flesh' is set, copy data etc. is loaded and the return value is 
+# a hash of 'circ' and 'marc_xml'.  Othwerwise, it's just a list of 
+# auch objects.
+sub fetch_user_circ_history {
+    my ($self, $flesh, $limit, $offset) = @_;
+    my $e = $self->editor;
+
+    my %limits = ();
+    $limits{offset} = $offset if defined $offset;
+    $limits{limit} = $limit if defined $limit;
+
+    my %flesh_ops = (
+        flesh => 3,
+        flesh_fields => {
+            auch => ['target_copy'],
+            acp => ['call_number'],
+            acn => ['record']
         },
-        from => 'au',
-        where => {id => $e->requestor->id}  
-        });
+    );
 
-    } else {
-       $circ_ids = $e->json_query({
-        select => {
-            au => [{
-                column => 'id', 
-                transform => 'action.usr_visible_circs', 
-                result_field => 'id'
-            }]
+    $e->xact_begin;
+    my $circs = $e->search_action_user_circ_history([
+        {usr => $e->requestor->id},
+        {   # order newest to oldest by default
+            order_by => {auch => 'xact_start DESC'},
+            $flesh ? %flesh_ops : (),
+            %limits
         },
-        from => 'au',
-        where => {id => $e->requestor->id}, 
-        limit => $limit,
-        offset => $offset
+        {substream => 1}
+    ]);
+    $e->rollback;
+
+    return $circs unless $flesh;
+
+    my @circs;
+    for my $circ (@$circs) {
+        push(@circs, {
+            circ => $circ, 
+            marc_xml => ($circ->target_copy->call_number->id != -1) ? 
+                XML::LibXML->new->parse_string(
+                    $circ->target_copy->call_number->record->marc) : 
+                undef  # pre-cat copy, use the dummy title/author instead
         });
     }
 
-    $ctx->{circs} = $self->fetch_user_circs(1, [map { $_->{id} } @$circ_ids]);
-    return Apache2::Const::OK;
+    return \@circs;
 }
 
 # TODO: action.usr_visible_holds does not return cancelled holds.  Should it?
@@ -2590,22 +2614,13 @@ sub load_myopac_circ_history_export {
     my $e = $self->editor;
     my $filename = $self->cgi->param('filename') || 'circ_history.csv';
 
-    my $ids = $e->json_query({
-        select => {
-            au => [{
-                column => 'id', 
-                transform => 'action.usr_visible_circs', 
-                result_field => 'id'
-            }]
-        },
-        from => 'au',
-        where => {id => $e->requestor->id} 
-    });
+    my $circs = $self->fetch_user_circ_history;
 
     $self->ctx->{csv} = $U->fire_object_event(
         undef, 
         'circ.format.history.csv',
-        $e->search_action_circulation({id => [map {$_->{id}} @$ids]}, {substream =>1}),
+        $e->search_action_circulation(
+            {id => [map {$_->id} @$circs]}, {substream =>1}),
         $self->editor->requestor->home_ou
     );