3 # A Class for hiding the ILS's concept of the item from the OpenSIP
7 package OpenILS::SIP::Item;
8 use strict; use warnings;
10 use Sys::Syslog qw(syslog);
13 use OpenILS::SIP::Transaction;
14 use OpenILS::Application::AppUtils;
15 use OpenILS::Application::Circ::ScriptBuilder;
17 my $U = 'OpenILS::Application::AppUtils';
22 my ($class, $item_id) = @_;
23 my $type = ref($class) || $class;
24 my $self = bless( {}, $type );
26 syslog('LOG_DEBUG', "OILS: Loading item $item_id...");
27 return undef unless $item_id;
29 my $e = OpenILS::SIP->editor();
31 my $copy = $e->search_asset_copy(
33 { barcode => $item_id },
37 acp => [ 'circ_lib', 'call_number', 'status' ],
38 acn => [ 'owning_lib', 'record' ],
48 syslog("LOG_DEBUG", "OILS: Item '%s' : not found", $item_id);
52 my ($circ) = $U->fetch_open_circulation($copy->id);
54 # if i am checked out, set $self->{patron} to the user's barcode
55 my $user = $e->retrieve_actor_user(
58 { flesh => 1, flesh_fields => { "au" => [ 'card' ] } }
62 my $bc = ($user) ? $user->card->barcode : "";
63 $self->{patron} = $bc;
64 $self->{patron_object} = $user;
66 syslog('LOG_DEBUG', "OILS: Open circulation exists on $item_id : user = $bc");
69 $self->{id} = $item_id;
70 $self->{copy} = $copy;
71 $self->{volume} = $copy->call_number;
72 $self->{record} = $copy->call_number->record;
73 $self->{mods} = $U->record_to_mvr($self->{record}) if $self->{record}->marc;
75 syslog("LOG_DEBUG", "OILS: Item('$item_id'): found with title '%s'", $self->title_id);
82 return 1 if $self->{ran_script};
83 $self->{ran_script} = 1;
85 my $config = OpenILS::SIP->config();
86 my $path = $config->{implementation_config}->{scripts}->{path};
87 my $item_config_script = $config->{implementation_config}->{scripts}->{item_config};
89 syslog('LOG_DEBUG', "OILS: Script path = $path, Item config script = $item_config_script");
92 OpenILS::Application::Circ::ScriptBuilder->build(
94 copy => $self->{copy},
95 editor => OpenILS::SIP->editor(),
99 $runner->add_path($path);
100 $runner->load($item_config_script);
102 unless( $self->{item_config_result} = $runner->run ) {
103 warn "Item config script [$path : $item_config_script] failed to run: $@\n";
104 syslog('LOG_ERR', "OILS: Item config script [$path : $item_config_script] failed to run: $@");
113 return 0 unless $self->run_attr_script;
114 syslog('LOG_DEBUG', "OILS: ITEM CONFIG => ". Dumper($self->{item_config_result}));
115 my $mag = $self->{item_config_result}->{magneticMedia};
116 syslog('LOG_DEBUG', "OILS: magnetic = $mag");
117 return ($mag and $mag eq 't') ? 1 : 0;
125 sub sip_item_properties {
131 my ($self, $props) = @_;
132 my $status = OpenILS::SIP::Transaction->new;
133 $self->{sip_item_properties} = $props;
146 return ($self->{mods}) ? $self->{mods}->title : $self->{copy}->dummy_title;
149 sub permanent_location {
151 return $self->{volume}->owning_lib->name;
154 sub current_location {
156 return $self->{copy}->circ_lib->name;
165 # 05 Charged; not to be recalled until earliest recall date
168 # 08 Waiting on hold shelf
169 # 09 Waiting to be re-shelved
170 # 10 In transit between library locations
171 # 11 Claimed returned
174 sub sip_circulation_status {
176 return '03' if $self->{copy}->status->name =~ /available/i;
177 return '04' if $self->{copy}->status->name =~ /checked out/i;
178 return '06' if $self->{copy}->status->name =~ /in process/i;
179 return '08' if $self->{copy}->status->name =~ /on holds shelf/i;
180 return '09' if $self->{copy}->status->name =~ /reshelving/i;
181 return '10' if $self->{copy}->status->name =~ /in transit/i;
182 return '12' if $self->{copy}->status->name =~ /lost/i;
186 sub sip_security_marker {
207 return $self->{volume}->owning_lib->name;
215 sub hold_queue_position {
216 my ($self, $patron_id) = @_;
222 my $e = OpenILS::SIP->editor();
224 my $circ = $e->search_action_circulation(
225 { target_copy => $self->{copy}->id, stop_fines => undef } )->[0];
228 # if not, lets look for other circs we can check in
229 $circ = $e->search_action_circulation(
231 target_copy => $self->{copy}->id,
232 xact_finish => undef,
233 stop_fines => [ 'CLAIMSRETURNED', 'LOST', 'LONGOVERDUE' ]
237 return $circ->due_date if $circ;
246 sub hold_pickup_date {
251 # message to display on console
254 return $self->{screen_msg} || '';
261 return $self->{print_line} || '';
265 # An item is available for a patron if
266 # 1) It's not checked out and (there's no hold queue OR patron
267 # is at the front of the queue)
269 # 2) It's checked out to the patron and there's no hold queue
271 my ($self, $for_patron) = @_;