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