]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/SIP/Item.pm
getting closer, still needs much love
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / SIP / Item.pm
1 #
2 #
3 # A Class for hiding the ILS's concept of the item from the OpenSIP
4 # system
5 #
6
7 package OpenILS::SIP::Item;
8
9 use strict;
10 use warnings;
11
12 use Sys::Syslog qw(syslog);
13
14 use OpenILS::SIP::Transaction;
15 use OpenILS::Application::AppUtils;
16 my $U = 'OpenILS::Application::AppUtils';
17
18 my %item_db;
19
20 sub new {
21     my ($class, $item_id) = @_;
22     my $type = ref($class) || $class;
23     my $self = {};
24     bless $self, $type;
25
26         require OpenILS::Utils::CStoreEditor;
27         my $e = OpenILS::Utils::CStoreEditor->new;
28
29         if(!UNIVERSAL::can($e, 'search_actor_card')) {
30                 syslog("LOG_WARNING", "Reloading CStoreEditor...");
31                 delete $INC{'OpenILS/Utils/CStoreEditor.pm'};
32                 require OpenILS::Utils::CStoreEditor;
33                 $e = OpenILS::Utils::CStoreEditor->new;
34         }
35
36
37          # FLESH ME
38          my $copy = $e->search_asset_copy(
39                 [
40                         { barcode => $item_id },
41                         {
42                                 flesh => 3,
43                                 flesh_fields => {
44                                         acp => [ 'circ_lib', 'call_number' ],
45                                         acn => [ 'owning_lib', 'record' ],
46                                 }
47                         }
48                 ]
49         );
50
51         if(!@$copy) {
52                 syslog("LOG_DEBUG", "OpenILS: Item '%s' : not found", $item_id);
53                 return undef;
54     }
55
56         $copy = $$copy[0];
57
58          # XXX See if i am checked out, if so set $self->{patron} to the user's barcode
59         my ($circ) = $U->fetch_open_circulation($copy->id);
60         if($circ) {
61                 my $user = $e->retrieve_actor_user(
62                         [
63                                 $circ->usr,
64                                 {
65                                         flesh => 1,
66                                         flesh_fields => {
67                                                 "au" => [ 'card' ],
68                                         }
69                                 }
70                         ]
71                 );
72
73                 my $bc = ($user) ? $user->card->barcode : "";
74                 $self->{patron} = $bc;
75                 $self->{patron_object} = $user;
76
77                 syslog('LOG_DEBUG', "Open circulation exists on $item_id : user = $bc");
78         }
79
80         $self->{id}                     = $item_id;
81         $self->{copy}           = $copy;
82         $self->{volume} = $copy->call_number;
83         $self->{record} = $copy->call_number->record;
84         
85         $self->{mods}   = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
86
87     syslog("LOG_DEBUG", "new OpenILS Item('%s'): found with title '%s'",
88            $item_id, $self->title_id);
89
90     return $self;
91 }
92
93 sub magnetic {
94     my $self = shift;
95          return 0;
96 }
97
98 sub sip_media_type {
99     my $self = shift;
100          return '001';
101 }
102
103 sub sip_item_properties {
104     my $self = shift;
105          return "";
106 }
107
108 sub status_update {
109     my ($self, $props) = @_;
110     my $status = new OpenILS::SIP::Transaction;
111     $self->{sip_item_properties} = $props;
112     $status->{ok} = 1;
113     return $status;
114 }
115
116
117 sub id {
118     my $self = shift;
119     return $self->{id};
120 }
121
122 sub title_id {
123     my $self = shift;
124     return ($self->{mods}) ? $self->{mods}->title : $self->{copy}->dummy_title;
125 }
126
127 sub permanent_location {
128     my $self = shift;
129          return $self->{volume}->owning_lib->name;
130 }
131
132 sub current_location {
133     my $self = shift;
134          return $self->{copy}->circ_lib->name;
135 }
136
137
138 # 2 chars 0-99 
139 sub sip_circulation_status {
140     my $self = shift;
141          return '01';
142 }
143
144 sub sip_security_marker {
145     return '02';
146 }
147
148 sub sip_fee_type {
149     return '01';
150 }
151
152 sub fee {
153     my $self = shift;
154          return 0;
155 }
156
157
158 sub fee_currency {
159     my $self = shift;
160     'CAD';
161 }
162
163 sub owner {
164     my $self = shift;
165          return $self->{volume}->owning_lib->name;
166 }
167
168 sub hold_queue {
169     my $self = shift;
170          return [];
171 }
172
173 sub hold_queue_position {
174     my ($self, $patron_id) = @_;
175          return 1;
176 }
177
178 sub due_date {
179     my $self = shift;
180          return 0;
181 }
182
183 sub recall_date {
184     my $self = shift;
185     return 0;
186 }
187
188 sub hold_pickup_date {
189     my $self = shift;
190          return 0;
191 }
192
193 # message to display on console
194 sub screen_msg {
195     my $self = shift;
196     return $self->{screen_msg} || '';
197 }
198
199
200 # reciept printer
201 sub print_line {
202      my $self = shift;
203      return $self->{print_line} || '';
204 }
205
206
207 # An item is available for a patron if
208 # 1) It's not checked out and (there's no hold queue OR patron
209 #    is at the front of the queue)
210 # OR
211 # 2) It's checked out to the patron and there's no hold queue
212 sub available {
213      my ($self, $for_patron) = @_;
214           return 1;
215 }
216
217
218 1;