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);
38 title => "Perl 5 desktop reference",
40 sip_media_type => '001',
45 title => "The deep blue alibi",
47 sip_media_type => '001',
52 title => "Harry Potter y el cáliz de fuego",
54 sip_media_type => '001',
62 defined $a->{priority} or return -1;
63 defined $b->{priority} or return 1;
64 return $a->{priority} <=> $b->{priority};
68 my ($class, $item_id) = @_;
69 my $type = ref($class) || $class;
71 my $item = GetBiblioFromItemNumber( GetItemnumberFromBarcode($item_id) );
74 syslog("LOG_DEBUG", "new ILS::Item('%s'): not found", $item_id);
75 warn "new ILS::Item($item_id) : No item '$item_id'.";
78 $item->{'id'} = $item->{'barcode'};
79 # check if its on issue and if so get the borrower
80 my $issue = GetItemIssue($item->{'itemnumber'});
81 my $borrower = GetMember($issue->{'borrowernumber'},'borrowernumber');
82 $item->{patron} = $borrower->{'cardnumber'};
83 my @reserves = (@{ GetReservesFromBiblionumber($item->{biblionumber}) });
84 $item->{hold_queue} = [ sort priority_sort @reserves ];
85 $item->{joetest} = 111;
89 syslog("LOG_DEBUG", "new ILS::Item('%s'): found with title '%s'",
90 $item_id, $self->{title});
97 return $self->{magnetic_media};
101 return $self->{sip_media_type};
103 sub sip_item_properties {
105 return $self->{sip_item_properties};
109 my ($self, $props) = @_;
110 my $status = new ILS::Transaction;
111 $self->{sip_item_properties} = $props;
122 return $self->{title};
124 sub permanent_location {
126 return $self->{permanent_location} || '';
128 sub current_location {
130 return $self->{current_location} || '';
133 sub sip_circulation_status {
135 if ($self->{patron}) {
137 } elsif (scalar @{$self->{hold_queue}}) {
144 sub sip_security_marker {
153 return $self->{fee} || 0;
157 return $self->{currency} || 'USD';
161 return 'CPL'; # FIXME: UWOLS was hardcoded
165 (defined $self->{hold_queue}) or return [];
166 return $self->{hold_queue};
169 sub hold_queue_position {
170 my ($self, $patron_id) = @_;
171 ($self->{hold_queue}) or return 0;
173 foreach (@{$self->{hold_queue}}) {
175 $_->{patron_id} or next;
176 if ($_->{patron_id} eq $patron_id) {
185 return $self->{due_date} || 0;
189 return $self->{recall_date} || 0;
191 sub hold_pickup_date {
193 return $self->{hold_pickup_date} || 0;
197 return $self->{screen_msg} || '';
201 return $self->{print_line} || '';
204 # An item is available for a patron if it is:
205 # 1) checked out to the same patron and there's no hold queue
207 # 2) not checked out and (there's no hold queue OR patron
208 # is at the front of the queue)
210 my ($self, $for_patron) = @_;
211 my $count = (defined $self->{hold_queue}) ? scalar @{$self->{hold_queue}} : 0;
212 print STDERR "availability check: hold_queue size $count\n";
213 if (defined($self->{patron_id})) {
214 ($self->{patron_id} eq $for_patron) or return 0;
215 return ($count ? 0 : 1);
216 } else { # not checked out
217 ($count) or return 1;
218 ($self->{hold_queue}[0] eq $for_patron) and return 1;