329c2fdbe043c5c59728fad5f5ca284e40c6a511
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Circ.pm
1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4
5 use OpenILS::Application::Circ::Rules;
6 use OpenILS::Application::Circ::Survey;
7 use OpenILS::Application::Circ::StatCat;
8 use OpenILS::Application::Circ::Holds;
9
10 use OpenILS::Application::AppUtils;
11 my $apputils = "OpenILS::Application::AppUtils";
12 use OpenSRF::Utils;
13 use OpenILS::Utils::ModsParser;
14
15
16 # ------------------------------------------------------------------------
17 # Top level Circ package;
18 # ------------------------------------------------------------------------
19
20 sub initialize {
21         my $self = shift;
22         OpenILS::Application::Circ::Rules->initialize();
23 }
24
25
26
27 # ------------------------------------------------------------------------
28 # Returns an array of {circ, record} hashes checked out by the user.
29 # ------------------------------------------------------------------------
30 __PACKAGE__->register_method(
31         method  => "checkouts_by_user",
32         api_name        => "open-ils.circ.actor.user.checked_out",
33 );
34
35 sub checkouts_by_user {
36         my( $self, $client, $user_session, $user_id ) = @_;
37
38         my $session = OpenSRF::AppSession->create("open-ils.storage");
39         my $user_obj = $apputils->check_user_session($user_session); 
40
41         if(!$user_id) { $user_id = $user_obj->id(); }
42
43         my $circs = $session->request(
44                 "open-ils.storage.direct.action.circulation.search.atomic",
45       { usr => $user_id, xact_finish => undef } );
46         $circs = $circs->gather(1);
47
48         my @results;
49         for my $circ (@$circs) {
50
51                 my $copy = $session->request(
52                         "open-ils.storage.direct.asset.copy.retrieve",
53                         $circ->target_copy );
54
55                 warn "Retrieving record for copy " . $circ->target_copy . "\n";
56
57                 my $record = $session->request(
58                         "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
59                         $circ->target_copy );
60
61                 $copy = $copy->gather(1);
62                 $record = $record->gather(1);
63
64 #               my $due_date = 
65 #                       OpenSRF::Utils->interval_to_seconds( 
66 #               $circ->duration ) + int(time());
67 #               $circ->due_date($due_date);
68
69                 use Data::Dumper;
70                 warn Dumper $circ;
71                 my $u = OpenILS::Utils::ModsParser->new();
72                 $u->start_mods_batch( $record->marc() );
73                 my $mods = $u->finish_mods_batch();
74                 $mods->doc_id($record->id());
75
76                 push( @results, { copy => $copy, circ => $circ, record => $mods } );
77         }
78
79         return \@results;
80
81 }
82
83
84
85
86
87
88
89 1;