From e3cf3c1daa1c80bba9dcaff8d1e540d12e61f186 Mon Sep 17 00:00:00 2001 From: morgane alonso Date: Thu, 25 Aug 2016 10:06:12 +0000 Subject: [PATCH] Bug 17047 ability to search subscription model on mana - add a class SharedContent.pm to communicate with mana server - add a link in serials-menu.inc to serials_search.pl to open a mana-subscription research form - modify the research form in serials-search.tt to show the right fields for mana - create datatable in mana-subscription-search-result.inc to show results from a research on mana - modify serials-search.pl to manage research on mana --- Koha/SharedContent.pm | 56 ++++++++++ .../includes/mana-subscription-search-result.inc | 40 +++++++ .../prog/en/includes/serials-menu.inc | 3 + .../prog/en/modules/serials/serials-home.tt | 1 + .../prog/en/modules/serials/serials-search.tt | 49 +++++++-- serials/serials-search.pl | 121 +++++++++++++++------ 6 files changed, 227 insertions(+), 43 deletions(-) create mode 100644 Koha/SharedContent.pm create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc diff --git a/Koha/SharedContent.pm b/Koha/SharedContent.pm new file mode 100644 index 0000000..ced0e6c --- /dev/null +++ b/Koha/SharedContent.pm @@ -0,0 +1,56 @@ +package Koha::SharedContent; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use JSON; +use HTTP::Request; +use LWP::UserAgent; + +our $MANA_IP = "http://10.25.159.107:5000"; + +sub manaRequest { + my $mana_request = shift; + my $result; + + $mana_request->content_type('application/json'); + my $userAgent = LWP::UserAgent->new; + my $response = $userAgent->request($mana_request); + + if ( $response->code ne "204" ) { + $result = from_json( $response->decoded_content ); + } + $result->{code} = $response->code; + + return $result if ( $response->code =~ /^2..$/ ); +} + +sub manaGetRequest { + my $resource = shift; + my $parameters = shift; + + $parameters = join '&', + map { defined $parameters->{$_} ? $_ . "=" . $parameters->{$_} : () } + keys %$parameters; + my $url = "$MANA_IP/$resource.json?$parameters"; + my $request = HTTP::Request->new( GET => $url ); + + return manaRequest($request); +} + +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc new file mode 100644 index 0000000..acaadec --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc @@ -0,0 +1,40 @@ +[% USE KohaDates %] + + + + + + + + + + + + + + + + + + + + + + + + + [% FOREACH subscription IN subscriptions %] + [% UNLESS subscription.cannotdisplay %] + + + + + + + + + + [% END %] + [% END %] + +
ISSNTitleFrequencyNumbering patternNumber of usersLast ImportActions
[% IF ( subscription.issn ) %][% subscription.issn %][% END %][% subscription.title %][% IF ( subscription.sfdescription ) %][% subscription.sfdescription %][% END %][% IF ( subscription.numberingmethod ) %][% subscription.numberingmethod %][% END %][% IF ( subscription.nbofusers ) %][% subscription.nbofusers %][% END %][% subscription.lastimport | $KohaDates %] Use
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc index 21dff3a..ee66508 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc @@ -31,4 +31,7 @@
  • Add subscription fields
  • + [% IF Koha.Preference('Mana') %] +
  • Search on Mana
  • + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt index eaafc94..f587b28 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt @@ -1,5 +1,6 @@ [% INCLUDE 'doc-head-open.inc' %] [% USE KohaDates %] +[% USE Koha %] Koha › Serials [% biblionumber %] [% INCLUDE 'doc-head-close.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt index 1728fb0..6131ed1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt @@ -1,6 +1,7 @@ [% USE Branches %] [% INCLUDE 'doc-head-open.inc' %] [% USE KohaDates %] +[% USE Koha %] [% USE AuthorisedValues %] Koha › Serials [% biblionumber %] [% INCLUDE 'doc-head-close.inc' %] @@ -10,6 +11,14 @@ @@ -123,6 +144,7 @@ [% END %] + [% IF ( mana ) %][% END %]
    @@ -130,13 +152,22 @@ [% END %] - [% IF ( done_searched ) %] - [% IF ( total ) %] -
    - + [% IF ( done_searched ) %] + [% IF ( total ) %] +
    + + [% IF mana %] +
    + [% INCLUDE 'mana-subscription-search-result.inc' %] +
    + [% ELSE %]
    [% IF openedsubscriptions %] @@ -354,6 +385,7 @@ [% END %] + [% END %] [% ELSE %]
    @@ -367,6 +399,7 @@
    [% INCLUDE 'serials-menu.inc' %] [% IF ( done_searched ) %] + [% UNLESS ( mana ) %]
    @@ -439,10 +472,12 @@
    +
    [% END %] + [% END %]
    [% INCLUDE 'intranet-bottom.inc' %] diff --git a/serials/serials-search.pl b/serials/serials-search.pl index 30bf7db..bd52cd7 100755 --- a/serials/serials-search.pl +++ b/serials/serials-search.pl @@ -38,6 +38,7 @@ use C4::Serials; use Koha::AdditionalField; use Koha::DateUtils; +use Koha::SharedContent; my $query = new CGI; my $title = $query->param('title_filter') || ''; @@ -52,6 +53,7 @@ my $location = $query->param('location_filter') || ''; my $expiration_date = $query->param('expiration_date_filter') || ''; my $routing = $query->param('routing') || C4::Context->preference("RoutingSerials"); my $searched = $query->param('searched') || 0; +my $mana = $query->param('mana') || 0; my @subscriptionids = $query->multi_param('subscriptionid'); my $op = $query->param('op'); @@ -95,7 +97,17 @@ for my $field ( @$additional_fields ) { my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef; my @subscriptions; if ($searched){ - @subscriptions = SearchSubscriptions( + if ($mana) { + my $result = Koha::SharedContent::manaGetRequest("subscription",{ + title => $title, + issn => $ISSN, + ean => $EAN, + publisher => $publisher + }); + @subscriptions = @{ $result->{data} }; + } + else { + @subscriptions = SearchSubscriptions( { biblionumber => $biblionumber, title => $title, @@ -108,46 +120,83 @@ if ($searched){ additional_fields => [ map{ { name => $_, value => $additional_field_filters->{$_}{value}, authorised_value_category => $additional_field_filters->{$_}{authorised_value_category} } } keys %$additional_field_filters ], location => $location, expiration_date => $expiration_date_dt, - } - ); + }); + } } -# to toggle between create or edit routing list options -if ($routing) { - for my $subscription ( @subscriptions) { - $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} ); - } +if ($mana) { + $template->param( + subscriptions => \@subscriptions, + total => scalar @subscriptions, + title_filter => $title, + ISSN_filter => $ISSN, + EAN_filter => $EAN, + callnumber_filter => $callnumber, + publisher_filter => $publisher, + bookseller_filter => $bookseller, + branch_filter => $branch, + location_filter => $location, + expiration_date_filter => $expiration_date_dt, + done_searched => $searched, + routing => $routing, + additional_field_filters => $additional_field_filters, + additional_fields_for_subscription => $additional_fields, + marcflavour => (uc(C4::Context->preference("marcflavour"))), + mana => $mana + ); } +else +{ + # to toggle between create or edit routing list options + if ($routing) { + for my $subscription ( @subscriptions) { + $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} ); + } + } -my (@openedsubscriptions, @closedsubscriptions); -for my $sub ( @subscriptions ) { - unless ( $sub->{closed} ) { - push @openedsubscriptions, $sub - unless $sub->{cannotdisplay}; - } else { - push @closedsubscriptions, $sub - unless $sub->{cannotdisplay}; + my (@openedsubscriptions, @closedsubscriptions); + for my $sub ( @subscriptions ) { + unless ( $sub->{closed} ) { + push @openedsubscriptions, $sub + unless $sub->{cannotdisplay}; + } else { + push @closedsubscriptions, $sub + unless $sub->{cannotdisplay}; + } } -} -$template->param( - openedsubscriptions => \@openedsubscriptions, - closedsubscriptions => \@closedsubscriptions, - total => @openedsubscriptions + @closedsubscriptions, - title_filter => $title, - ISSN_filter => $ISSN, - EAN_filter => $EAN, - callnumber_filter => $callnumber, - publisher_filter => $publisher, - bookseller_filter => $bookseller, - branch_filter => $branch, - location_filter => $location, - expiration_date_filter => $expiration_date_dt, - done_searched => $searched, - routing => $routing, - additional_field_filters => $additional_field_filters, - additional_fields_for_subscription => $additional_fields, - marcflavour => (uc(C4::Context->preference("marcflavour"))) -); + my $branches = GetBranches(); + my @branches_loop; + foreach (sort keys %$branches){ + my $selected = 0; + $selected = 1 if( defined $branch and $branch eq $_ ); + push @branches_loop, { + branchcode => $_, + branchname => $branches->{$_}->{'branchname'}, + selected => $selected, + }; + } + $template->param( + openedsubscriptions => \@openedsubscriptions, + closedsubscriptions => \@closedsubscriptions, + total => @openedsubscriptions + @closedsubscriptions, + title_filter => $title, + ISSN_filter => $ISSN, + EAN_filter => $EAN, + callnumber_filter => $callnumber, + publisher_filter => $publisher, + bookseller_filter => $bookseller, + branch_filter => $branch, + location_filter => $location, + expiration_date_filter => $expiration_date_dt, + branches_loop => \@branches_loop, + done_searched => $searched, + routing => $routing, + additional_field_filters => $additional_field_filters, + additional_fields_for_subscription => $additional_fields, + marcflavour => (uc(C4::Context->preference("marcflavour"))), + mana => $mana + ); +} output_html_with_http_headers $query, $cookie, $template->output; -- 2.7.4