@@ -, +, @@ - add a class SharedContent.pm to communicate with Mana-KB server - add a link in serials-menu.inc to serials_search.pl to open - modify the research form in serials-search.tt to show the right fields - create datatable in mana-subscription-search-result.inc to show - modify serials-search.pl to manage research on Mana-KB - add a mana_id to subscription table - add a share button on serials-toolbar.inc and a modal to ask - add function in C4/Serials to get all the info for a subscription - modify subscription-detail.pl to manage sharing to Mana-KB - modify subscription-add.tt and subscription.pl to manage a - add 2 script in svc for ajax calling from subscription-add.tt - add a function in Subscription.pm to have all the info for a Mana-KB research - modify functions used by subscription-add.pl in C4/Serials to manage a --- Koha/SharedContent.pm | 90 ++++++++++++++++++++++ Koha/Subscription/Frequencies.pm | 57 ++++++++++++++ Koha/Subscription/Frequency.pm | 48 ++++++++++++ Koha/Subscription/Numberpattern.pm | 48 ++++++++++++ Koha/Subscription/Numberpatterns.pm | 77 ++++++++++++++++++ .../mana_01-add_mana_id_in_subscription.sql | 1 + .../includes/mana-subscription-search-result.inc | 46 +++++++++++ .../serials/mana-subscription-search-result.tt | 1 + svc/mana/search | 62 +++++++++++++++ svc/mana/use | 48 ++++++++++++ t/db_dependent/Serials/GetFictiveIssueNumber.t | 1 - 11 files changed, 478 insertions(+), 1 deletion(-) create mode 100644 Koha/SharedContent.pm create mode 100644 Koha/Subscription/Frequencies.pm create mode 100644 Koha/Subscription/Frequency.pm create mode 100644 Koha/Subscription/Numberpattern.pm create mode 100644 Koha/Subscription/Numberpatterns.pm create mode 100644 installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt create mode 100755 svc/mana/search create mode 100755 svc/mana/use --- a/Koha/SharedContent.pm +++ a/Koha/SharedContent.pm @@ -0,0 +1,90 @@ +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 manaNewUserPatchRequest { + my $resource = shift; + my $id = shift; + + my $url = "$MANA_IP/$resource/$id.json/newUser"; + my $request = HTTP::Request->new( PATCH => $url ); + + return manaRequest($request); +} + +sub manaPostRequest { + my $resource = shift; + my $content = shift; + + my $url = "$MANA_IP/$resource.json"; + my $request = HTTP::Request->new( POST => $url ); + + $content->{bulk_import} = 0; + my $json = to_json( $content, { utf8 => 1 } ); + $request->content($json); + + return manaRequest($request); +} + +sub manaGetRequestWithId { + my $resource = shift; + my $id = shift; + + my $url = "$MANA_IP/$resource/$id.json"; + my $request = HTTP::Request->new( GET => $url ); + + return manaRequest($request); +} + +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; --- a/Koha/Subscription/Frequencies.pm +++ a/Koha/Subscription/Frequencies.pm @@ -0,0 +1,57 @@ +package Koha::Subscription::Frequencies; + +# 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 Koha::Database; +use Koha::Subscription::Frequency; +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Subscription::Frequencies - Koha Subscription::Frequency object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionFrequency'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Subscription::Frequency'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; --- a/Koha/Subscription/Frequency.pm +++ a/Koha/Subscription/Frequency.pm @@ -0,0 +1,48 @@ +package Koha::Subscription::Frequency; + +# 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 Koha::Database; +use base qw(Koha::Object); + +=head1 NAME + +Koha::Subscription::Frequency - Koha Subscription::Frequency Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionFrequency'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; --- a/Koha/Subscription/Numberpattern.pm +++ a/Koha/Subscription/Numberpattern.pm @@ -0,0 +1,48 @@ +package Koha::Subscription::Numberpattern; + +# 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 Koha::Database; +use base qw(Koha::Object); + +=head1 NAME + +Koha::SubscriptionNumberpattern - Koha SubscriptionNumberpattern Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionNumberpattern'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; --- a/Koha/Subscription/Numberpatterns.pm +++ a/Koha/Subscription/Numberpatterns.pm @@ -0,0 +1,77 @@ +package Koha::Subscription::Numberpatterns; + +# 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 Koha::Database; +use Koha::Subscription::Numberpattern; +use base qw(Koha::Objects); + +=head1 NAME + +Koha::SubscriptionNumberpatterns - Koha SubscriptionNumberpattern object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 uniqeLabel + +=cut + +sub uniqueLabel { + my ($self, $label) = @_; + + my $samelabel = Koha::Subscription::Numberpatterns->search({label => $label})->next(); + if ($samelabel) { + my $i = 2; + my $newlabel = $samelabel->label . " ($i)"; + while (my $othersamelabel = $self->search({label => $newlabel})->next()) { + $i++; + $newlabel = $samelabel->label . " ($i)"; + } + $label = $newlabel; + } + return $label; +} + +=head3 type + +=cut + +sub _type { + return 'SubscriptionNumberpattern'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Subscription::Numberpattern'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; --- a/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql +++ a/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql @@ -0,0 +1, @@ +ALTER TABLE subscription ADD mana_id int(11); --- a/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc @@ -0,0 +1,46 @@ +[% USE KohaDates %] + + + + + + + + + + [% UNLESS search_only %] + + [% END %] + + + + + + + + + + + [% UNLESS search_only %] + + [% END %] + + + + [% FOREACH subscription IN subscriptions %] + [% UNLESS subscription.cannotdisplay %] + + + + + + + + [% UNLESS search_only %] + + [% END %] + + [% 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
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt @@ -0,0 +1, @@ +[% INCLUDE 'mana-subscription-search-result.inc' %] --- a/svc/mana/search +++ a/svc/mana/search @@ -0,0 +1,62 @@ +#!/usr/bin/perl + +# 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, see . +# + +use strict; +use warnings; + +use Koha::SharedContent; +use Koha::Subscription; +use C4::Auth qw(check_cookie_auth), qw(get_template_and_user); +use C4::Output qw( output_with_http_headers ); + +use CGI; +use JSON; + +my $input = new CGI; + +my ( $auth_status, $sessionID ) = + check_cookie_auth( $input->cookie('CGISESSID'), + { serials => 'create_subscription' } ); + +if ( $auth_status ne "ok" ) { + exit 0; +} + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "serials/mana-subscription-search-result.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + + # flagsrequired => { serials => $permission }, + flagsrequired => { serials => 'create_subscription' }, + debug => 1, + } +); + +my $biblionumber = $input->param('biblionumber'); + +my $sub_mana_info = Koha::Subscription::get_search_info($biblionumber); +my $result = + Koha::SharedContent::manaGetRequest( "subscription", $sub_mana_info ); +$template->param( subscriptions => $result->{data} ); + +output_with_http_headers $input, $cookie, $template->output, 'json'; --- a/svc/mana/use +++ a/svc/mana/use @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +# 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, see . +# + +use strict; +use warnings; + +use Koha::SharedContent; +use C4::Auth qw(check_cookie_auth); + +use CGI; +use JSON; + + +my $input = new CGI; +binmode STDOUT, ":encoding(UTF-8)"; +print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); + +my ( $auth_status, $sessionID ) = + check_cookie_auth( $input->cookie('CGISESSID'), + { serials => 'create_subscription' } ); + +if ( $auth_status ne "ok" ) { + exit 0; +} + +my $result = Koha::SharedContent::manaGetRequestWithId("subscription", $input->param('id') ); + +my $subscription; +$subscription = $result->{data}; + +print(to_json($subscription)); --- a/t/db_dependent/Serials/GetFictiveIssueNumber.t +++ a/t/db_dependent/Serials/GetFictiveIssueNumber.t @@ -1,6 +1,5 @@ #!/usr/bin/perl - use C4::Context; use Test::More tests => 18; use Modern::Perl; --