]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
movin on, adding exceptions, more more more
[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 use OpenILS::Application::Circ::Money;
10
11 use OpenILS::Application::AppUtils;
12 my $apputils = "OpenILS::Application::AppUtils";
13 use OpenSRF::Utils;
14 use OpenILS::Utils::ModsParser;
15
16
17 # ------------------------------------------------------------------------
18 # Top level Circ package;
19 # ------------------------------------------------------------------------
20
21 sub initialize {
22         my $self = shift;
23         OpenILS::Application::Circ::Rules->initialize();
24 }
25
26
27
28 # ------------------------------------------------------------------------
29 # Returns an array of {circ, record} hashes checked out by the user.
30 # ------------------------------------------------------------------------
31 __PACKAGE__->register_method(
32         method  => "checkouts_by_user",
33         api_name        => "open-ils.circ.actor.user.checked_out",
34         NOTES           => <<"  NOTES");
35         Returns a list of open circulations as a pile of objects.  each object
36         contains the relevant copy, circ, and record
37         NOTES
38
39 sub checkouts_by_user {
40         my( $self, $client, $user_session, $user_id ) = @_;
41
42         my $session = OpenSRF::AppSession->create("open-ils.storage");
43         my $user_obj = $apputils->check_user_session($user_session); 
44
45         if(!$user_id) { $user_id = $user_obj->id(); }
46
47         my $circs = $session->request(
48                 "open-ils.storage.direct.action.open_circulation.search.usr.atomic", $user_id );
49         $circs = $circs->gather(1);
50
51         my @results;
52         for my $circ (@$circs) {
53
54                 my $copy = $session->request(
55                         "open-ils.storage.direct.asset.copy.retrieve",
56                         $circ->target_copy );
57
58                 warn "Retrieving record for copy " . $circ->target_copy . "\n";
59
60                 my $record = $session->request(
61                         "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
62                         $circ->target_copy );
63
64                 $copy = $copy->gather(1);
65                 $record = $record->gather(1);
66
67                 use Data::Dumper;
68                 warn Dumper $circ;
69                 my $u = OpenILS::Utils::ModsParser->new();
70                 $u->start_mods_batch( $record->marc() );
71                 my $mods = $u->finish_mods_batch();
72                 $mods->doc_id($record->id());
73
74                 push( @results, { copy => $copy, circ => $circ, record => $mods } );
75         }
76
77         return \@results;
78
79 }
80
81
82 __PACKAGE__->register_method(
83         method  => "title_from_transaction",
84         api_name        => "open-ils.circ.circ_transaction.find_title",
85         NOTES           => <<"  NOTES");
86         Returns a mods object for the title that is linked to from the 
87         copy from the hold that created the given transaction
88         NOTES
89
90 sub title_from_transaction {
91
92         my( $self, $client, $login_session, $transactionid ) = @_;
93         my $user = $apputils->check_user_session($login_session); 
94         my $session = OpenSRF::AppSession->create('open-ils.storage');
95
96         my $circ = $session->request(
97                 "open-ils.storage.direct.action.circulation.retrieve", $transactionid )->gather(1);
98
99         if($circ) {
100                 my $title = $session->request(
101                         "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
102                         $circ->target_copy )->gather(1);
103
104                 if($title) {
105                         my $u = OpenILS::Utils::ModsParser->new();
106                         $u->start_mods_batch( $title->marc );
107                         return $u->finish_mods_batch();
108                 }
109         }
110
111         return undef;   
112 }
113
114
115
116
117
118 1;