From: Colin Campbell Date: Wed, 4 Sep 2013 10:18:11 +0000 (+0100) Subject: Bug 10817: return hold items info in SIP Patron Info Response X-Git-Url: http://git.rot13.org/?p=koha.git;a=commitdiff_plain;h=63820d3973dae7514556172665a46c0584aaefc8 Bug 10817: return hold items info in SIP Patron Info Response When requested by the summary flags the sipserver should return in the patron info response barcodes of the relevant titles. For available holds this is the barcode of the captured items. For unavailable holds ( i.e. current unsatisfied holds ), we need to send a barcode so that the unit can use this to request the title info. The barcode could be any one belonging to the title. This patch also corrects the erroneous return of empty items in the patron information response. If the unit supplies a range 1 - 100 unless the title has a hundred or more copies the unit expects all copies. The server was erroneously stuffing the returned arrays with null copies so that all summary requests returned 100 copies (mainly without barcodes) Signed-off-by: Chris Cormack Signed-off-by: Katrin Fischer Testing notes: Using the test script provided on the bug report, but changed it to match sip user and patron existing in my database. Before applying the patch the SIP responses show the behaviour pointed out above regarding the 100 items. After applying the patch and restarting the SIP server responses are much more clean not returning empty IDs. 64 Patron information response AS = hold items hold items count is correct. AS contains barcodes of waiting holds. Before patch, all AS were empty. AT = overdue items overdue items count is correct. AT contains barcodes of overdue items. AU = charged items charged items count is correct. AU contains barcodes of charged items. AV = fine items Judging from behaviour seen and comment in Patrons.pm currently not implemented. BU = recall items Recalls are not implemented in Koha yet. CD = unavailable hold items unavailable items count is correct. CD contains barcode for item level holds and is empty for title level holds where no item can be determined. Before patch, all CD were empty. Signed-off-by: Galen Charlton --- diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index ac24d2fd53..b9f06599e4 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -22,6 +22,7 @@ use C4::Members; use C4::Reserves; use C4::Branch qw(GetBranchName); use Digest::MD5 qw(md5_base64); +use C4::Items qw( GetBarcodeFromItemnumber GetItemnumbersForBiblio); our $VERSION = 3.07.00.049; @@ -91,8 +92,8 @@ sub new { screen_msg => 'Greetings from Koha. ' . $kp->{opacnote}, print_line => '', items => [], - hold_items => $flags->{WAITING}{itemlist}, - overdue_items => $flags->{ODUES}{itemlist}, + hold_items => $flags->{WAITING}->{itemlist}, + overdue_items => $flags->{ODUES}->{itemlist}, fine_items => [], recall_items => [], unavail_holds => [], @@ -114,8 +115,7 @@ sub new { } # FIXME: populate fine_items recall_items -# $ilspatron{hold_items} = (GetReservesFromBorrowernumber($kp->{borrowernumber},'F')); - $ilspatron{unavail_holds} = [(GetReservesFromBorrowernumber($kp->{borrowernumber}))]; + $ilspatron{unavail_holds} = _get_outstanding_holds($kp->{borrowernumber}); $ilspatron{items} = GetPendingIssues($kp->{borrowernumber}); $self = \%ilspatron; $debug and warn Dumper($self); @@ -248,12 +248,25 @@ sub x_items { my $self = shift; my $array_var = shift or return; my ($start, $end) = @_; - $self->{$array_var} or return []; - $start = 1 unless defined($start); - $end = scalar @{$self->{$array_var}} unless defined($end); - # syslog("LOG_DEBUG", "$array_var: start = %d, end = %d; items(%s)", $start, $end, join(', ', @{$self->{items}})); - return [@{$self->{$array_var}}[$start-1 .. $end-1]]; + my $item_list = []; + if ($self->{$array_var}) { + if ($start && $start > 1) { + --$start; + } + else { + $start = 0; + } + if ( $end && $end < @{$self->{$array_var}} ) { + } + else { + $end = @{$self->{$array_var}}; + --$end; + } + @{$item_list} = @{$self->{$array_var}}[ $start .. $end ]; + + } + return $item_list; } # @@ -261,7 +274,11 @@ sub x_items { # sub hold_items { my $self = shift; - return $self->x_items('hold_items', @_); + my $item_arr = $self->x_items('hold_items', @_); + foreach my $item (@{$item_arr}) { + $item->{barcode} = GetBarcodeFromItemnumber($item->{itemnumber}); + } + return $item_arr; } sub overdue_items { @@ -365,6 +382,24 @@ sub _get_address { return $address; } +sub _get_outstanding_holds { + my $borrowernumber = shift; + my @hold_array = grep { !defined $_->{found} || $_->{found} ne 'W'} GetReservesFromBorrowernumber($borrowernumber); + foreach my $h (@hold_array) { + my $item; + if ($h->{itemnumber}) { + $item = $h->{itemnumber}; + } + else { + # We need to return a barcode for the biblio so the client + # can request the biblio info + $item = ( GetItemnumbersForBiblio($h->{biblionumber}) )[0]; + } + $h->{barcode} = GetBarcodeFromItemnumber($item); + } + return \@hold_array; +} + 1; __END__