=head1 DESCRIPTION
Each function in this module represents an ILS-DI service.
-They all takes a CGI instance as argument and most of them return a
+They all takes a CGI instance as argument and most of them return a
hashref that will be printed by XML::Simple in opac/ilsdi.pl
=head1 SYNOPSIS
- use C4::ILSDI::Services;
- use XML::Simple;
- use CGI qw ( -utf8 );
+ use C4::ILSDI::Services;
+ use XML::Simple;
+ use CGI qw ( -utf8 );
- my $cgi = new CGI;
+ my $cgi = new CGI;
- $out = LookupPatron($cgi);
+ $out = LookupPatron($cgi);
- print CGI::header('text/xml');
- print XMLout($out,
- noattr => 1,
- noescape => 1,
- nosort => 1,
+ print CGI::header('text/xml');
+ print XMLout($out,
+ noattr => 1,
+ noescape => 1,
+ nosort => 1,
xmldecl => '<?xml version="1.0" encoding="UTF-8" ?>',
- RootName => 'LookupPatron',
- SuppressEmpty => 1);
+ RootName => 'LookupPatron',
+ SuppressEmpty => 1);
=cut
=head2 GetAvailability
-Given a set of biblionumbers or itemnumbers, returns a list with
+Given a set of biblionumbers or itemnumbers, returns a list with
availability of the items associated with the identifiers.
Parameters:
=head3 id_type (Required)
-defines the type of record identifier being used in the request,
+defines the type of record identifier being used in the request,
possible values:
- bib
=head3 return_type (Optional)
-requests a particular level of detail in reporting availability,
+requests a particular level of detail in reporting availability,
possible values:
- bib
=head3 return_fmt (Optional)
-requests a particular format or set of formats in reporting
-availability
+requests a particular format or set of formats in reporting
+availability
=cut
=head2 GetRecords
-Given a list of biblionumbers, returns a list of record objects that
+Given a list of biblionumbers, returns a list of record objects that
contain bibliographic information, as well as associated holdings and item
-information. The caller may request a specific metadata schema for the
+information. The caller may request a specific metadata schema for the
record objects to be returned.
-This function behaves similarly to HarvestBibliographicRecords and
-HarvestExpandedRecords in Data Aggregation, but allows quick, real time
+This function behaves similarly to HarvestBibliographicRecords and
+HarvestExpandedRecords in Data Aggregation, but allows quick, real time
lookup by bibliographic identifier.
You can use OAI-PMH ListRecords instead of this service.
Parameters:
- id (Required)
- list of system record identifiers
+ list of system record identifiers
- id_type (Optional)
- Defines the metadata schema in which the records are returned,
- possible values:
- - MARCXML
+ Defines the metadata schema in which the records are returned,
+ possible values:
+ - MARCXML
=cut
foreach my $biblionumber ( split( / /, $cgi->param('id') ) ) {
# Get the biblioitem from the biblionumber
- my $biblioitem = ( GetBiblioItemByBiblioNumber( $biblionumber, undef ) )[0];
- if ( not $biblioitem->{'biblionumber'} ) {
- $biblioitem->{code} = "RecordNotFound";
+ my $biblio = Koha::Biblios->find( $biblionumber );
+ unless ( $biblio ) {
+ push @records, { code => "RecordNotFound" };
+ next;
}
+ my $biblioitem = $biblio->biblioitem->unblessed;
+
my $embed_items = 1;
my $record = GetMarcBiblio({
biblionumber => $biblionumber,
# Get most of the needed data
my $biblioitemnumber = $biblioitem->{'biblioitemnumber'};
- my $biblio = Koha::Biblios->find( $biblionumber );
my $holds = $biblio->current_holds->unblessed;
my $issues = GetBiblioIssues($biblionumber);
my $items = GetItemsByBiblioitemnumber($biblioitemnumber);
=head2 GetAuthorityRecords
-Given a list of authority record identifiers, returns a list of record
-objects that contain the authority records. The function user may request
+Given a list of authority record identifiers, returns a list of record
+objects that contain the authority records. The function user may request
a specific metadata schema for the record objects.
Parameters:
Parameters:
- id (Required)
- an identifier used to look up the patron in Koha
+ an identifier used to look up the patron in Koha
- id_type (Optional)
- the type of the identifier, possible values:
- - cardnumber
- - firstname
- - userid
- - borrowernumber
+ the type of the identifier, possible values:
+ - cardnumber
+ - userid
+ - email
+ - borrowernumber
+ - firstname
+ - surname
=cut
sub LookupPatron {
my ($cgi) = @_;
- my $patrons = Koha::Patrons->search( { $cgi->param('id_type') => $cgi->param('id') } );
+ my $id = $cgi->param('id');
+ if(!$id) {
+ return { message => 'PatronNotFound' };
+ }
+
+ my $patrons;
+ my $passed_id_type = $cgi->param('id_type');
+ if($passed_id_type) {
+ $patrons = Koha::Patrons->search( { $passed_id_type => $id } );
+ } else {
+ foreach my $id_type ('cardnumber', 'userid', 'email', 'borrowernumber',
+ 'surname', 'firstname') {
+ $patrons = Koha::Patrons->search( { $id_type => $id } );
+ last if($patrons->count);
+ }
+ }
unless ( $patrons->count ) {
return { message => 'PatronNotFound' };
}
=head2 AuthenticatePatron
-Authenticates a user's login credentials and returns the identifier for
+Authenticates a user's login credentials and returns the identifier for
the patron.
Parameters:
my ($status, $cardnumber, $userid) = C4::Auth::checkpw( C4::Context->dbh, $username, $password );
if ( $status ) {
# Get the borrower
- my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
+ my $patron = Koha::Patrons->find( { userid => $userid } );
return { id => $patron->borrowernumber };
}
else {
=head2 GetPatronInfo
-Returns specified information about the patron, based on options in the
-request. This function can optionally return patron's contact information,
+Returns specified information about the patron, based on options in the
+request. This function can optionally return patron's contact information,
fine information, hold request information, and loan information.
Parameters:
- patron_id (Required)
- the borrowernumber
+ the borrowernumber
- show_contact (Optional, default 1)
- whether or not to return patron's contact information in the response
+ whether or not to return patron's contact information in the response
- show_fines (Optional, default 0)
- whether or not to return fine information in the response
+ whether or not to return fine information in the response
- show_holds (Optional, default 0)
- whether or not to return hold request information in the response
+ whether or not to return hold request information in the response
- show_loans (Optional, default 0)
- whether or not to return loan information request information in the response
+ whether or not to return loan information request information in the response
=cut
# Cleaning the borrower hashref
my $borrower = $patron->unblessed;
- my $flags = C4::Members::patronflags( $borrower );
- $borrower->{'charges'} = $flags->{'CHARGES'}->{'amount'};
+ $borrower->{charges} = sprintf "%.02f", $patron->account->non_issues_charges; # FIXME Formatting should not be done here
my $library = Koha::Libraries->find( $borrower->{branchcode} );
$borrower->{'branchname'} = $library ? $library->branchname : '';
delete $borrower->{'userid'};
# Issues management
if ( $cgi->param('show_loans') && $cgi->param('show_loans') eq "1" ) {
- my $issues = GetPendingIssues($borrowernumber);
- foreach my $issue ( @$issues ){
- $issue->{'issuedate'} = $issue->{'issuedate'}->strftime('%Y-%m-%d %H:%M');
- $issue->{'date_due'} = $issue->{'date_due'}->strftime('%Y-%m-%d %H:%M');
+ my $pending_checkouts = $patron->pending_checkouts;
+ my @checkouts;
+ while ( my $c = $pending_checkouts->next ) {
+ # FIXME We should only retrieve what is needed in the template
+ my $issue = $c->unblessed_all_relateds;
+ push @checkouts, $issue
}
- $borrower->{'loans'}->{'loan'} = $issues;
+ $borrower->{'loans'}->{'loan'} = \@checkouts;
}
if ( $cgi->param('show_attributes') eq "1" ) {
- my $attrs = GetBorrowerAttributes( $borrowernumber, 0, 1 );
+ my $attrs = GetBorrowerAttributes( $borrowernumber, 1 );
$borrower->{'attributes'} = $attrs;
}
Parameters:
- patron_id (Required)
- the borrower ID
+ the borrower ID
=cut
=head2 GetServices
-Returns information about the services available on a particular item for
+Returns information about the services available on a particular item for
a particular patron.
Parameters:
- patron_id (Required)
- a borrowernumber
+ a borrowernumber
- item_id (Required)
- an itemnumber
+ an itemnumber
=cut
# Reserve level management
my $biblionumber = $item->{'biblionumber'};
my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
- if ($canbookbereserved eq 'OK') {
+ if ($canbookbereserved->{status} eq 'OK') {
push @availablefor, 'title level hold';
my $canitembereserved = IsAvailableForItemLevelRequest($item, $borrower);
if ($canitembereserved) {
my $barcode = $item->{'barcode'} || '';
$barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
if ($barcode) {
- my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, $barcode );
+ my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode );
# TODO push @availablefor, 'loan';
}
Parameters:
- patron_id (Required)
- a borrowernumber
+ a borrowernumber
- item_id (Required)
- an itemnumber
+ an itemnumber
- desired_due_date (Required)
- the date the patron would like the item returned by
+ the date the patron would like the item returned by
=cut
Parameters:
- patron_id (Required)
- a borrowernumber
+ a borrowernumber
- bib_id (Required)
- a biblionumber
+ a biblionumber
- request_location (Required)
- IP address where the end user request is being placed
+ IP address where the end user request is being placed
- pickup_location (Optional)
- a branch code indicating the location to which to deliver the item for pickup
+ a branch code indicating the location to which to deliver the item for pickup
- needed_before_date (Optional)
- date after which hold request is no longer needed
+ date after which hold request is no longer needed
- pickup_expiry_date (Optional)
- date after which item returned to shelf if item is not picked up
+ date after which item returned to shelf if item is not picked up
=cut
my $title = $biblio ? $biblio->title : '';
# Check if the biblio can be reserved
- return { code => 'NotHoldable' } unless CanBookBeReserved( $borrowernumber, $biblionumber ) eq 'OK';
+ return { code => 'NotHoldable' } unless CanBookBeReserved( $borrowernumber, $biblionumber )->{status} eq 'OK';
my $branch;
=head2 HoldItem
-Creates, for a borrower, an item-level hold request on a specific item of
+Creates, for a borrower, an item-level hold request on a specific item of
a bibliographic record in Koha.
Parameters:
- patron_id (Required)
- a borrowernumber
+ a borrowernumber
- bib_id (Required)
- a biblionumber
+ a biblionumber
- item_id (Required)
- an itemnumber
+ an itemnumber
- pickup_location (Optional)
- a branch code indicating the location to which to deliver the item for pickup
+ a branch code indicating the location to which to deliver the item for pickup
- needed_before_date (Optional)
- date after which hold request is no longer needed
+ date after which hold request is no longer needed
- pickup_expiry_date (Optional)
- date after which item returned to shelf if item is not picked up
+ date after which item returned to shelf if item is not picked up
=cut
# Check for item disponibility
my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber );
my $canbookbereserved = C4::Reserves::CanBookBeReserved( $borrowernumber, $biblionumber );
- return { code => 'NotHoldable' } unless $canbookbereserved eq 'OK' and $canitembereserved eq 'OK';
+ return { code => 'NotHoldable' } unless $canbookbereserved->{status} eq 'OK' and $canitembereserved->{status} eq 'OK';
# Pickup branch management
my $branch;
# Get the reserve or return an error code
my $reserve_id = $cgi->param('item_id');
- my $reserve = C4::Reserves::GetReserve($reserve_id);
- return { code => 'RecordNotFound' } unless $reserve;
- return { code => 'RecordNotFound' } unless ($reserve->{borrowernumber} == $borrowernumber);
+ my $hold = Koha::Holds->find( $reserve_id );
+ return { code => 'RecordNotFound' } unless $hold;
+ return { code => 'RecordNotFound' } unless ($hold->borrowernumber == $borrowernumber);
- C4::Reserves::CancelReserve({reserve_id => $reserve_id});
+ $hold->cancel;
return { code => 'Canceled' };
}