]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/SIP/Item.pm
adding
[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                 $self->{patron} = $user->card->barcode if $user;
74                 $self->{patron_object} = $user;
75         }
76
77         $self->{id}                     = $item_id;
78         $self->{copy}           = $copy;
79         $self->{volume} = $copy->call_number;
80         $self->{record} = $copy->call_number->record;
81         
82         $self->{mods}   = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
83
84     syslog("LOG_DEBUG", "new OpenILS Item('%s'): found with title '%s'",
85            $item_id, $self->title_id);
86
87     return $self;
88 }
89
90 sub magnetic {
91     my $self = shift;
92          return 0;
93 }
94
95 sub sip_media_type {
96     my $self = shift;
97          return '001';
98 }
99
100 sub sip_item_properties {
101     my $self = shift;
102          return "";
103 }
104
105 sub status_update {
106     my ($self, $props) = @_;
107     my $status = new OpenILS::SIP::Transaction;
108     $self->{sip_item_properties} = $props;
109     $status->{ok} = 1;
110     return $status;
111 }
112
113
114 sub id {
115     my $self = shift;
116     return $self->{id};
117 }
118
119 sub title_id {
120     my $self = shift;
121     return ($self->{mods}) ? $self->{mods}->title : $self->{copy}->dummy_title;
122 }
123
124 sub permanent_location {
125     my $self = shift;
126          return $self->{volume}->owning_lib->name;
127 }
128
129 sub current_location {
130     my $self = shift;
131          return $self->{copy}->circ_lib->name;
132 }
133
134
135 # 2 chars 0-99 
136 sub sip_circulation_status {
137     my $self = shift;
138          return '01';
139 }
140
141 sub sip_security_marker {
142     return '02';
143 }
144
145 sub sip_fee_type {
146     return '01';
147 }
148
149 sub fee {
150     my $self = shift;
151          return 0;
152 }
153
154
155 sub fee_currency {
156     my $self = shift;
157     'CAD';
158 }
159
160 sub owner {
161     my $self = shift;
162          return $self->{volume}->owning_lib->name;
163 }
164
165 sub hold_queue {
166     my $self = shift;
167          return [];
168 }
169
170 sub hold_queue_position {
171     my ($self, $patron_id) = @_;
172          return 1;
173 }
174
175 sub due_date {
176     my $self = shift;
177          return 0;
178 }
179
180 sub recall_date {
181     my $self = shift;
182     return 0;
183 }
184
185 sub hold_pickup_date {
186     my $self = shift;
187          return 0;
188 }
189
190 # message to display on console
191 sub screen_msg {
192     my $self = shift;
193     return $self->{screen_msg} || '';
194 }
195
196
197 # reciept printer
198 sub print_line {
199      my $self = shift;
200      return $self->{print_line} || '';
201 }
202
203
204 # An item is available for a patron if
205 # 1) It's not checked out and (there's no hold queue OR patron
206 #    is at the front of the queue)
207 # OR
208 # 2) It's checked out to the patron and there's no hold queue
209 sub available {
210      my ($self, $for_patron) = @_;
211           return 1;
212 }
213
214
215 1;