Koha/opac/opac-idref.pl
Fridolin Somers 1beb65ed4f Bug 19640: fix OPAC IdRef webservice display
The OPAC webservice IdRef display was broken.
The call returns results but citations where empty.
Maybe the webservice has changed.

This patch corrects the fetch of datas in result.
Also fixes a small HTML missing tag tr.
Also adds a comment with link to official doc :
http://documentation.abes.fr/aideidrefdeveloppeur/index.html#MicroWebBiblio

Test plan :
1) Enable system preference IdRef
2) Choose an existing PPN like 032581270
3) Look result on : https://www.idref.fr/services/biblio/032581270.json
4) Call in OPAC website : /cgi-bin/koha/opac-idref.pl?unimarc3=032581270
5) Without patch you see only one role containing empty rows
6) With patch you see all roles with correct rows

Signed-off-by: Simon Pouchol <simon.pouchol@biblibre.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Amended: removed unused @unimarc3 (not to be confused with $unimarc3).

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-12-07 09:37:09 -03:00

92 lines
2.4 KiB
Perl
Executable file

#!/usr/bin/perl
# This file is part of Koha.
#
# Copyright (C) 2014 BibLibre
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use CGI;
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON;
use Encode;
use C4::Auth;
use C4::Context;
use C4::Search;
use C4::Output;
my $cgi = new CGI;
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{
template_name => "opac-idref.tt",
query => $cgi,
type => "opac",
authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
}
);
my $ua = LWP::UserAgent->new;
# See http://documentation.abes.fr/aideidrefdeveloppeur/index.html#MicroWebBiblio
my $base = 'http://www.idref.fr/services/biblio/';
my $unimarc3 = $cgi->param('unimarc3');
my $request = HTTP::Request->new(
'GET',
$base . $unimarc3 . ".json",
);
$request->protocol('HTTP/1.1');
my $response = $ua->request($request);
if ( not $response->is_success) {
$template->param(error => $base.$unimarc3.'.json');
output_html_with_http_headers $cgi, $cookie, $template->output;
exit;
}
my $content = Encode::decode("utf8", $response->content);
my $json = from_json( $content );
my $r;
my @results = ref $json->{sudoc}{result} eq "ARRAY"
? @{ $json->{sudoc}{result} }
: ($json->{sudoc}{result});
for my $result (@results) {
my $role_node = $result->{'role'};
my @roles =
ref $role_node eq "ARRAY"
? @$role_node
: ($role_node);
for my $role (@roles) {
my @docs = ref $role->{doc} eq "ARRAY"
? @{ $role->{doc} }
: $role->{doc};
push @$r,
{
role_name => $role->{roleName},
count => $role->{count},
docs => \@docs,
};
}
}
$template->param(
content => $r,
unimarc3 => $unimarc3,
);
output_html_with_http_headers $cgi, $cookie, $template->output;