Koha/opac/opac-idref.pl
Jonathan Druart 6af69c2648 Bug 8992: Interfacing with the Idref webservice
On the detail page (in the opac), if the biblio comes from the Sudoc,
you must have a link (on the right of the author link) which open a popup with
informations about this author (publications by role).

To test:

1/ Switch on the Idref system preference

2/ Simulate a SUDOC record:
  Fill a 7..$3 field with a ppn (032581270 for example).
  Fill the 009 field with an integer

3/ Go to the opac detail page of this notice.
You should see the IDREF link.
If you click on it, a popup displays a loading icon and after a few
seconds (depending of the productivity of the authority :)), a list of
roles. For each role, a table displays all his corresponding publications.

4/ On the right, you have 2 links: 1 for a koha search for this result
and 1 for a SUDOC link

Signed-off-by: valerie bertrand <valerie.bertrand@univ-lyon3.fr>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2015-04-28 15:46:26 -03:00

102 lines
2.8 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 ),
flagsrequired => { borrow => 1 },
}
);
my $ua = LWP::UserAgent->new;
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 $role_name;
my @unimarc3;
my @results = ref $json->{sudoc}{result} eq "ARRAY"
? @{ $json->{sudoc}{result} }
: ($json->{sudoc}{result});
for my $role_node ( @results ) {
while ( my ( $k, $v ) = each %$role_node ) {
next unless $k eq "role";
my $role_name;
my $count = 0;
my $role_data = {};
my @nodes = ref $v eq "ARRAY"
? @$v
: ($v);
for my $node ( @nodes ) {
while ( ( $k, $v ) = each %$node ) {
if ( $k eq 'roleName' ) {
$role_name = $v;
$role_data->{role_name} = $role_name;
}
elsif ( $k eq 'count' ) {
$role_data->{count} = $v;
}
elsif ( $k eq 'doc' ) {
push @{ $role_data->{docs} }, $v;
}
}
}
push @$r, $role_data;
}
}
$template->param(
content => $r,
unimarc3 => $unimarc3,
);
output_html_with_http_headers $cgi, $cookie, $template->output;