adding more permissions and exceptions related to the additions of more accurate...
[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 #      { 
46 #                       usr => $user_id, 
47 #                       xact_finish => undef, 
48 #                       stop_fines => [ undef, "MAXFINES", "LONGOVERDUE" ],
49 #               }, 
50 #               { order_by => "due_date" } );
51
52         my $circs = $session->request(
53                 "open-ils.storage.direct.action.open_circulation.search.usr.atomic", $user_id );
54         $circs = $circs->gather(1);
55
56
57         my @results;
58         for my $circ (@$circs) {
59
60                 my $copy = $session->request(
61                         "open-ils.storage.direct.asset.copy.retrieve",
62                         $circ->target_copy );
63
64                 warn "Retrieving record for copy " . $circ->target_copy . "\n";
65
66                 my $record = $session->request(
67                         "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
68                         $circ->target_copy );
69
70                 $copy = $copy->gather(1);
71                 $record = $record->gather(1);
72
73                 use Data::Dumper;
74                 warn Dumper $circ;
75                 my $u = OpenILS::Utils::ModsParser->new();
76                 $u->start_mods_batch( $record->marc() );
77                 my $mods = $u->finish_mods_batch();
78                 $mods->doc_id($record->id());
79
80                 push( @results, { copy => $copy, circ => $circ, record => $mods } );
81         }
82
83         return \@results;
84
85 }
86
87
88
89
90
91
92
93 1;