Bugzilla – Attachment 45363 Details for
Bug 15292
Libris (Swedish national catalogue) item status service
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15292 - Libris ILS-DI item status (service)
Bug-15292---Libris-ILS-DI-item-status-service.patch (text/plain), 6.14 KB, created by
Martin Persson
on 2015-12-03 15:47:25 UTC
(
hide
)
Description:
Bug 15292 - Libris ILS-DI item status (service)
Filename:
MIME Type:
Creator:
Martin Persson
Created:
2015-12-03 15:47:25 UTC
Size:
6.14 KB
patch
obsolete
>From c972b5a216c6d51bd7a627cc294a279f28624046 Mon Sep 17 00:00:00 2001 >From: Martin Persson <xarragon@gmail.com> >Date: Thu, 3 Dec 2015 16:18:18 +0100 >Subject: [PATCH] Bug 15292 - Libris ILS-DI item status (service) > >This patch adds the GetLibrisAvailability method >to the ILS-DI service module. > >Sponsored-By: Halland County Library >--- > C4/ILSDI/Services.pm | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 141 insertions(+) > >diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm >index e69c070..090b7a3 100644 >--- a/C4/ILSDI/Services.pm >+++ b/C4/ILSDI/Services.pm >@@ -34,6 +34,8 @@ use HTML::Entities; > use CGI qw ( -utf8 ); > use DateTime; > use C4::Auth; >+use MARC::Record; >+use XML::Writer; > > =head1 NAME > >@@ -154,6 +156,56 @@ sub GetAvailability { > return $out; > } > >+=head2 GetLibrisAvailability >+ >+Returns item status for items from the Swedish national >+catalogue LIBRIS. Given a unique id stored in control-field 001, >+item status for all copies are returned as XML. >+ >+=head3 id (Required) >+ >+The LIBRIS id of the bibliographic item. >+This number is completely separate from ISBN or internal Koha ids. >+It can be found in MARC control-field 001, indexed by Zebra. >+ >+=cut >+ >+sub GetLibrisAvailability { >+ my ( $cgi ) = @_; >+ >+ # Prepare XML header and output. >+ my $xsi_ns = 'http://www.w3.org/2001/XMLSchema-instance'; >+ my $item_ns = 'http://appl.libris.kb.se/LIBRISItem.xsd'; >+ >+ my $writer = XML::Writer->new( OUTPUT => 'self', >+ ENCODING => 'utf-8' ); >+ $writer->xmlDecl(); >+ >+ my $libris_id = $cgi->param( 'id' ); >+ >+ # Retrieve availability info: >+ my ( $info, $error ) = _libris_availability( $libris_id ); >+ if ( not defined $info ) { >+ $writer->dataElement( 'Error', $error ); >+ } else { >+ foreach my $item (@{ $info->items }) { >+ $writer->startTag( >+ 'Item_Information', >+ 'xmlns:xsi' => $xsi_ns, >+ 'xsi:noNamespaceSchema' => $item_ns ); >+ $writer->dataElement( 'Item_No', $item->{'item_no'} ); >+ $writer->dataElement( 'Location', $item->{'location'} ); >+ $writer->dataElement( 'Call_No', $item->{'call_no'} ); >+ $writer->dataElement( 'Status', $item->{'status'} ); >+ $writer->dataElement( 'Status_Date_Description', $item->{'status_date_desc'} ); >+ $writer->dataElement( 'Status_Date', $item->{'status_date'} ); >+ $writer->dataElement( 'UniqueItemId', $item->{'unique_id'} ); >+ $writer->endTag(); >+ } >+ } >+ return $writer->end(); # Calling 'end' returns the XML output. >+} >+ > =head2 GetRecords > > Given a list of biblionumbers, returns a list of record objects that >@@ -781,4 +833,93 @@ sub _availability { > } > } > >+=head2 _libris_availability >+ >+Returns, for an LIBRIS (Swedish national catalogue) ID, >+an array containing availability information. >+ >+my ( $result, $errmsg ) = _libris_availability; >+$result will be undefined on error, $errmsg will be set. >+ >+=cut >+ >+sub _libris_availability >+{ >+ my ( $libris_id ) = @_; >+ >+ return ( undef, "Missing parameter: Libris id" ) unless defined $libris_id; >+ >+ my ($error, $results, $count) = C4::Search::SimpleSearch( $libris_id, 0, 1 ); >+ >+ if ($count < 1 || scalar @{ $results } < 1) { >+ return ( undef, "No search results for Libris id $libris_id" ); >+ } >+ >+ my $xml = @{ $results }[0]; >+ my $marcflavor = C4::Context->preference( 'marcflavour' ); >+ my $record = MARC::Record->new_from_xml( $xml, 'utf8', $marcflavor ); >+ my $biblionumber = $record->subfield( '999', 'c' ); >+ >+ if (defined $biblionumber) { >+ # Possible enhancement; verify ontrol-field 003 is either 'LIBRIS' or 'SE-LIBR'. >+ my @kohaitems = GetItemsInfo( $biblionumber ); >+ >+ my ( $status, $status_date, $status_date_desc ); >+ >+ my @items; >+ foreach my $kohaitem ( @kohaitems ) { >+ # Convert Koha status to Libris equivalent. >+ if ( exists $kohaitem->{'notforloan'} ) { >+ $status = 'Not for loan'; >+ >+ } elsif ( exists $kohaitem->{'onloan'} ) { >+ $status = 'On loan'; >+ if ( defined $kohaitem->{'datelastborrowed'} ) { >+ $status_date = $kohaitem->{'datedue'}; >+ $status_date_desc = 'Due on'; >+ } >+ >+ } elsif ( exists $kohaitem->{'itemlost'} ) { >+ $status = 'Item lost'; >+ if ( defined $kohaitem->{'itemlost_on'} ) { >+ $status_date = $kohaitem->{'itemlost_on'}; >+ $status_date_desc = 'Item lost on'; >+ } >+ >+ } elsif ( exists $kohaitem->{'withdrawn'} ) { >+ $status = 'Withdrawn'; >+ if (defined $kohaitem->{'withdrawn_om'} ) { >+ $status_date = $kohaitem->{'withdrawn_on'}; >+ $status_date_desc = 'Withdrawn on'; >+ } >+ } elsif ( exists $kohaitem->{'damaged'} ) { >+ $status = 'Damaged'; >+ } else { >+ $status = 'Available'; >+ } >+ >+ # No date set yet, fall back to 'date last seen': >+ if ( not defined $status_date and defined $kohaitem->{'datelastseen'} ) { >+ $status_date_desc = 'Last seen on'; >+ $status_date = $kohaitem->{'datelastseen'}; >+ } >+ my $item = { >+ location => $kohaitem->{'branchname'}, >+ status => $status, >+ status_date => $status_date, >+ status_date_desc => $status_date_desc, >+ call_number => $kohaitem->{'itemcallnumber'}, >+ item_id => $kohaitem->{'copynumber'}, >+ unique_item_id => $kohaitem->{'barcode'}, >+ }; >+ push( @items, $item ); >+ } >+ >+ my $result = { 'items' => @items }; >+ return ( $result, undef ); >+ } >+ >+ return ( undef, "Mo item information for $libris_id with biblionumber $biblionumber" ); >+} >+ > 1; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15292
:
45358
|
45359
|
45360
| 45363