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