From 1cce1437447393ae2a520248a4361a2d3ffacee5 Mon Sep 17 00:00:00 2001
From: erickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Tue, 1 Mar 2011 16:20:52 +0000
Subject: [PATCH] merging in some useful changes from the opac-tt-poc branch,
 including capture of authtime in CStoreEditor, some holds retrieval
 de-fleshing options, and a total_count field added to user opac vital stats
 api

git-svn-id: svn://svn.open-ils.org/ILS/trunk@19549 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 .../src/perlmods/lib/OpenILS/Application/Actor.pm  |  4 +-
 .../perlmods/lib/OpenILS/Application/Circ/Holds.pm | 45 ++++++++++++----------
 .../src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm | 22 +++++++++--
 3 files changed, 46 insertions(+), 25 deletions(-)

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
index ff38f3b115..d8dfb71677 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
@@ -34,7 +34,7 @@ use OpenILS::Application::Actor::Stage;
 
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Utils::Penalty;
-use List::Util qw/max/;
+use List::Util qw/max reduce/;
 
 use UUID::Tiny qw/:std/;
 
@@ -1592,6 +1592,8 @@ sub user_opac_vitals {
         ->run($auth => $user_id);
     return $out if (defined($U->event_code($out)));
 
+    $out->{"total_out"} = reduce { $a + $out->{$b} } 0, qw/out overdue long_overdue/;
+
     return {
         user => {
             first_given_name  => $user->first_given_name,
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
index b85864b0d1..74957f1845 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
@@ -2635,10 +2635,10 @@ __PACKAGE__->register_method(
 );
 
 sub uber_hold {
-	my($self, $client, $auth, $hold_id) = @_;
+	my($self, $client, $auth, $hold_id, $args) = @_;
 	my $e = new_editor(authtoken=>$auth);
 	$e->checkauth or return $e->event;
-    return uber_hold_impl($e, $hold_id);
+    return uber_hold_impl($e, $hold_id, $args);
 }
 
 __PACKAGE__->register_method(
@@ -2649,17 +2649,16 @@ __PACKAGE__->register_method(
 );
 
 sub batch_uber_hold {
-	my($self, $client, $auth, $hold_ids) = @_;
+	my($self, $client, $auth, $hold_ids, $args) = @_;
 	my $e = new_editor(authtoken=>$auth);
 	$e->checkauth or return $e->event;
-    $client->respond(uber_hold_impl($e, $_)) for @$hold_ids;
+    $client->respond(uber_hold_impl($e, $_, $args)) for @$hold_ids;
     return undef;
 }
 
 sub uber_hold_impl {
-    my($e, $hold_id) = @_;
-
-	my $resp = {};
+    my($e, $hold_id, $args) = @_;
+    $args ||= {};
 
 	my $hold = $e->retrieve_action_hold_request(
 		[
@@ -2688,27 +2687,33 @@ sub uber_hold_impl {
 	my $user = $hold->usr;
 	$hold->usr($user->id);
 
-	my $card = $e->retrieve_actor_card($user->card)
-		or return $e->event;
 
-	my( $mvr, $volume, $copy ) = find_hold_mvr($e, $hold);
+	my( $mvr, $volume, $copy, $issuance, $bre ) = find_hold_mvr($e, $hold, $args->{suppress_mvr});
 
-	flesh_hold_notices([$hold], $e);
-	flesh_hold_transits([$hold]);
+	flesh_hold_notices([$hold], $e) unless $args->{suppress_notices};
+	flesh_hold_transits([$hold]) unless $args->{suppress_transits};
 
     my $details = retrieve_hold_queue_status_impl($e, $hold);
 
-    return {
+    my $resp = {
         hold           => $hold,
         copy           => $copy,
         volume         => $volume,
-        mvr            => $mvr,
-        patron_first   => $user->first_given_name,
-        patron_last    => $user->family_name,
-        patron_barcode => $card->barcode,
-        patron_alias   => $user->alias,
         %$details
     };
+
+    $resp->{mvr} = $mvr unless $args->{suppress_mvr};
+    unless($args->{suppress_patron_details}) {
+	    my $card = $e->retrieve_actor_card($user->card) or return $e->event;
+        $resp->{patron_first}   = $user->first_given_name,
+        $resp->{patron_last}    = $user->family_name,
+        $resp->{patron_barcode} = $card->barcode,
+        $resp->{patron_alias}   = $user->alias,
+    };
+
+    $resp->{bre} = $bre if $args->{include_bre};
+
+    return $resp;
 }
 
 
@@ -2718,7 +2723,7 @@ sub uber_hold_impl {
 # hold is all about
 # -----------------------------------------------------
 sub find_hold_mvr {
-	my( $e, $hold ) = @_;
+	my( $e, $hold, $no_mvr ) = @_;
 
 	my $tid;
 	my $copy;
@@ -2767,7 +2772,7 @@ sub find_hold_mvr {
 
     # TODO return metarcord mvr for M holds
 	my $title = $e->retrieve_biblio_record_entry($tid);
-	return ( $U->record_to_mvr($title), $volume, $copy, $issuance );
+	return ( ($no_mvr) ? undef : $U->record_to_mvr($title), $volume, $copy, $issuance, $title );
 }
 
 __PACKAGE__->register_method(
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm
index ff298f42d1..03237caf3a 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm
@@ -115,11 +115,19 @@ sub log {
 sub checkauth {
 	my $self = shift;
 	$self->log(D, "checking auth token ".$self->authtoken);
-	my ($reqr, $evt) = $U->checkses($self->authtoken);
-	$self->event($evt) if $evt;
-	return $self->{requestor} = $reqr;
-}
 
+	my $content = $U->simplereq( 
+		'open-ils.auth', 
+		'open-ils.auth.session.retrieve', $self->authtoken, 1);
+
+    if(!$content or $U->event_code($content)) {
+        $self->event( ($content) ? $content : OpenILS::Event->new('NO_SESSION'));
+        return undef;
+    }
+
+    $self->{authtime} = $content->{authtime};
+	return $self->{requestor} = $content->{userobj};
+}
 
 =head test
 sub checkauth {
@@ -177,6 +185,12 @@ sub authtoken {
 	return $self->{authtoken};
 }
 
+sub authtime {
+	my( $self, $auth ) = @_;
+	$self->{authtime} = $auth if $auth;
+	return $self->{authtime};
+}
+
 sub timeout {
     my($self, $to) = @_;
     $self->{timeout} = $to if defined $to;
-- 
2.11.0