4 # A Class for hiding the ILS's concept of the item from the OpenSIP
13 use Sys::Syslog qw(syslog);
25 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
37 title => "Perl 5 desktop reference",
39 sip_media_type => '001',
44 title => "The deep blue alibi",
46 sip_media_type => '001',
51 title => "Harry Potter y el cáliz de fuego",
53 sip_media_type => '001',
61 defined $a->{priority} or return -1;
62 defined $b->{priority} or return 1;
63 return $a->{priority} <=> $b->{priority};
67 my ($class, $item_id) = @_;
68 my $type = ref($class) || $class;
70 my $item = GetBiblioFromItemNumber( GetItemnumberFromBarcode($item_id) );
73 syslog("LOG_DEBUG", "new ILS::Item('%s'): not found", $item_id);
74 warn "new ILS::Item($item_id) : No item '$item_id'.";
77 $item->{'id'} = $item->{'barcode'};
78 # check if its on issue and if so get the borrower
79 my $issue = GetItemIssue($item->{'itemnumber'});
80 my $borrower = GetMember($issue->{'borrowernumber'},'borrowernumber');
81 $item->{patron} = $borrower->{'cardnumber'};
82 my @reserves = (@{ GetReservesFromBiblionumber($item->{biblionumber}) });
83 $item->{hold_queue} = [ sort priority_sort @reserves ];
84 $item->{joetest} = 111;
88 syslog("LOG_DEBUG", "new ILS::Item('%s'): found with title '%s'",
89 $item_id, $self->{title});
96 return $self->{magnetic_media};
100 return $self->{sip_media_type};
102 sub sip_item_properties {
104 return $self->{sip_item_properties};
108 my ($self, $props) = @_;
109 my $status = new ILS::Transaction;
110 $self->{sip_item_properties} = $props;
121 return $self->{title};
123 sub permanent_location {
125 return $self->{permanent_location} || '';
127 sub current_location {
129 return $self->{current_location} || '';
132 sub sip_circulation_status {
134 if ($self->{patron}) {
136 } elsif (scalar @{$self->{hold_queue}}) {
143 sub sip_security_marker {
152 return $self->{fee} || 0;
156 return $self->{currency} || 'USD';
160 return 'CPL'; # FIXME: UWOLS was hardcoded
164 (defined $self->{hold_queue}) or return [];
165 return $self->{hold_queue};
168 sub hold_queue_position {
169 my ($self, $patron_id) = @_;
170 ($self->{hold_queue}) or return 0;
172 foreach (@{$self->{hold_queue}}) {
174 $_->{patron_id} or next;
175 if ($_->{patron_id} eq $patron_id) {
184 return $self->{due_date} || 0;
188 return $self->{recall_date} || 0;
190 sub hold_pickup_date {
192 return $self->{hold_pickup_date} || 0;
196 return $self->{screen_msg} || '';
200 return $self->{print_line} || '';
203 # An item is available for a patron if it is:
204 # 1) checked out to the same patron and there's no hold queue
206 # 2) not checked out and (there's no hold queue OR patron
207 # is at the front of the queue)
209 my ($self, $for_patron) = @_;
210 my $count = (defined $self->{hold_queue}) ? scalar @{$self->{hold_queue}} : 0;
211 print STDERR "availability check: hold_queue size $count\n";
212 if (defined($self->{patron_id})) {
213 ($self->{patron_id} eq $for_patron) or return 0;
214 return ($count ? 0 : 1);
215 } else { # not checked out
216 ($count) or return 1;
217 ($self->{hold_queue}[0] eq $for_patron) and return 1;