From e02db382f13e218209090eebe808affebb2ff5a8 Mon Sep 17 00:00:00 2001 From: morgane alonso Date: Thu, 25 Aug 2016 14:18:42 +0000 Subject: [PATCH] Bug 17047 ability to share a subscription to mana - add a mana_id to subscription table - add a share button on serials-toolbar.inc and a modal to ask the language of the share and to alert if the subscription is already link to a mana subscription model - add function in C4/Serials to get all the info for a subscription sharing - modify subscription-detail.pl to manage sharing to mana --- C4/Serials.pm | 8 +- Koha/SharedContent.pm | 14 +++ Koha/Subscription.pm | 51 ++++++++++ .../mana_01-add_mana_id_in_subscription.sql | 1 + .../prog/en/includes/serials-toolbar.inc | 108 +++++++++++++++++++++ .../prog/en/modules/serials/subscription-detail.tt | 16 ++- serials/subscription-detail.pl | 71 +++++++++++--- 7 files changed, 251 insertions(+), 18 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql diff --git a/C4/Serials.pm b/C4/Serials.pm index 543b1dc..885192e 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1402,7 +1402,7 @@ sub NewSubscription { $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, - $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype + $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id ) = @_; my $dbh = C4::Context->dbh; @@ -1416,8 +1416,8 @@ sub NewSubscription { irregularity, numberpattern, locale, callnumber, manualhistory, internalnotes, serialsadditems, staffdisplaycount, opacdisplaycount, graceperiod, location, enddate, skip_serialseq, - itemtype, previousitemtype) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + itemtype, previousitemtype, mana_id) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?) |; my $sth = $dbh->prepare($query); $sth->execute( @@ -1428,7 +1428,7 @@ sub NewSubscription { $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, - $itemtype, $previousitemtype + $itemtype, $previousitemtype, $mana_id ); my $subscriptionid = $dbh->{'mysql_insertid'}; diff --git a/Koha/SharedContent.pm b/Koha/SharedContent.pm index ced0e6c..81a6a3e 100644 --- a/Koha/SharedContent.pm +++ b/Koha/SharedContent.pm @@ -40,6 +40,20 @@ sub manaRequest { return $result if ( $response->code =~ /^2..$/ ); } +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 manaGetRequest { my $resource = shift; my $parameters = shift; diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm index 332a018..29a2c66 100644 --- a/Koha/Subscription.pm +++ b/Koha/Subscription.pm @@ -22,6 +22,12 @@ use Modern::Perl; use Carp; use Koha::Database; +use Koha::Biblios; +use Koha::Biblioitems; +use Koha::Subscriptions; +use Koha::Subscription::Frequencies; +use Koha::Subscription::Numberpatterns; +use JSON; use base qw(Koha::Object); @@ -39,6 +45,51 @@ Koha::Subscription - Koha Subscription Object class =cut +sub get_sharable_info { + my $shared_sub_id = shift; + my $subscription = Koha::Subscriptions->find($shared_sub_id); + my $biblio = Koha::Biblios->find( $subscription->biblionumber ); + my $biblioitem = Koha::Biblioitems->find( + { 'biblionumber' => $subscription->biblionumber } ); + my $sub_frequency = + Koha::Subscription::Frequencies->find( $subscription->periodicity ); + my $sub_numberpatteern = + Koha::Subscription::Numberpatterns->find( $subscription->numberpattern ); + + my $sub_mana_info = { + 'title' => $biblio->title, + 'sfdescription' => $sub_frequency->description, + 'unit' => $sub_frequency->unit, + 'unitsperissue' => $sub_frequency->unitsperissue, + 'issuesperunit' => $sub_frequency->issuesperunit, + 'label' => $sub_numberpatteern->label, + 'sndescription' => $sub_numberpatteern->description, + 'numberingmethod' => $sub_numberpatteern->numberingmethod, + 'label1' => $sub_numberpatteern->label1, + 'add1' => $sub_numberpatteern->add1, + 'every1' => $sub_numberpatteern->every1, + 'whenmorethan1' => $sub_numberpatteern->whenmorethan1, + 'setto1' => $sub_numberpatteern->setto1, + 'numbering1' => $sub_numberpatteern->numbering1, + 'label2' => $sub_numberpatteern->label2, + 'add2' => $sub_numberpatteern->add2, + 'every2' => $sub_numberpatteern->every2, + 'whenmorethan2' => $sub_numberpatteern->whenmorethan2, + 'setto2' => $sub_numberpatteern->setto2, + 'numbering2' => $sub_numberpatteern->numbering2, + 'label3' => $sub_numberpatteern->label3, + 'add3' => $sub_numberpatteern->add3, + 'every3' => $sub_numberpatteern->every3, + 'whenmorethan3' => $sub_numberpatteern->whenmorethan3, + 'setto3' => $sub_numberpatteern->setto3, + 'numbering3' => $sub_numberpatteern->numbering3, + 'issn' => $biblioitem->issn, + 'ean' => $biblioitem->ean, + 'publishercode' => $biblioitem->publishercode + }; + return $sub_mana_info; +} + sub _type { return 'Subscription'; } diff --git a/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql b/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql new file mode 100644 index 0000000..5c590d1 --- /dev/null +++ b/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql @@ -0,0 +1 @@ +ALTER TABLE subscription ADD mana_id int(11); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc index b368317..c2aaee2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc @@ -13,6 +13,9 @@ window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=reopen"; } } + function share() { + window.location="subscription-detail.pl?subscriptionid=[% subscriptionid %]&op=share"; + } $(document).ready(function() { $("#deletesub").click(function(){ @@ -43,6 +46,13 @@ [% ELSE %]
New subscription
[% END %] + [% IF Koha.Preference('Mana') %] + [% IF one_language_enabled==0 or mana_id %] +
Share
+ [% ELSE %] +
Share
+ [% END %] + [% END %] [% END %] [% IF ( CAN_user_serials_edit_subscription || CAN_user_serials_create_subscription || CAN_user_serials_delete_subscription ) %] @@ -99,3 +109,101 @@ [% END %] [% END %] + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt index 157c135..52daa78 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt @@ -1,6 +1,7 @@ [% USE Koha %] [% USE Branches %] [% USE AuthorisedValues %] +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] Koha › Serials › Details for subscription #[% subscriptionid %] [% INCLUDE 'doc-head-close.inc' %] @@ -41,7 +42,7 @@ $(document).ready(function() {
- [% INCLUDE 'serials-toolbar.inc' %] + [% INCLUDE 'serials-toolbar.inc' mana_id = mana_id %]

Subscription for [% bibliotitle%] [% IF closed %](closed)[% END %]

[% IF ( abouttoexpire ) %] @@ -70,7 +71,18 @@ $(document).ready(function() {
- [% END %] + [% END %] + [% IF mana_code.defined %] +
+

+ [% IF (mana_code == 201) %] + The export is done, thank you for your contribution. + [% ELSIF (mana_code == 200) %] + The model already exists on Mana, thank you for your contribution. + [% END %] +

+
+ [% END %]
    diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index 824ffc2..6bfa85d 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -32,6 +32,12 @@ use Koha::Acquisition::Bookseller; use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/; use Carp; +use LWP::UserAgent; +use Koha::SharedContent; +use Koha::Patrons; +use Koha::Subscriptions; +use Koha::Libraries; + my $query = new CGI; my $op = $query->param('op') || q{}; my $issueconfirmed = $query->param('issueconfirmed'); @@ -67,31 +73,72 @@ my ($totalissues,@serialslist) = GetSerials($subscriptionid); $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue) if ($op eq 'del') { - if ($$subs{'cannotedit'}){ - carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed"; - print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); - exit; - } - + if ($$subs{'cannotedit'}){ + carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed"; + print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); + exit; + } + # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid); my $linkedissues = CountIssues($subscriptionid); my $countitems = HasItems($subscriptionid); if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) { - $template->param(NEEDSCONFIRMATION => 1); - if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); } - if ($linkedissues > 0) { $template->param("LINKEDISSUES" => 1); } - if ($countitems > 0) { $template->param("LINKEDITEMS" => 1); } + $template->param(NEEDSCONFIRMATION => 1); + if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); } + if ($linkedissues > 0) { $template->param("LINKEDISSUES" => 1); } + if ($countitems > 0) { $template->param("LINKEDITEMS" => 1); } } else { - $issueconfirmed = "1"; + $issueconfirmed = "1"; } # If it's ok to delete the subscription, we do so if ($issueconfirmed eq "1") { - &DelSubscription($subscriptionid); + &DelSubscription($subscriptionid); print $query->redirect("/cgi-bin/koha/serials/serials-home.pl"); exit; } } +elsif ( $op and $op eq "share" ) { + my $mana_language; + if ( $query->param('mana_language') ) { + $mana_language = $query->param('mana_language'); + } + else { + $mana_language = C4::Context->preference('language'); + } + + my $mana_email; + if ( $loggedinuser ne 0 ) { + my $borrower = Koha::Patrons->find($loggedinuser); + $mana_email = $borrower->email + if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); + $mana_email = $borrower->emailpro + if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); + $mana_email = + Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail + if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); + } + $mana_email = C4::Context->preference('KohaAdminEmailAddress') + if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); + my %versions = C4::Context::get_versions(); + + my $mana_info = { + language => $mana_language, + kohaversion => $versions{'kohaVersion'}, + exportemail => $mana_email + }; + my $sub_mana_info = Koha::Subscription::get_sharable_info($subscriptionid); + $sub_mana_info = { %$sub_mana_info, %$mana_info }; + my $result = Koha::SharedContent::manaPostRequest( "subscription", + $sub_mana_info ); + if ( $result->{code} eq "200" and $result->{code} eq "201" ) { + my $subscription = Koha::Subscriptions->find($subscriptionid); + $subscription->set( { mana_id => $result->{id} } )->store; + $subs->{mana_id} = $result->{id}; + } + $template->param( mana_code => $result->{code} ); +} + my $hasRouting = check_routing($subscriptionid); (undef, $cookie, undef, undef) -- 2.7.4