From 791335e309e22a2024b345eb7551c23d4a6ff607 Mon Sep 17 00:00:00 2001 From: morgane alonso Date: Thu, 25 Aug 2016 08:22:50 +0000 Subject: [PATCH] Bug 17047 subscriptions management with Mana-KB - add a class SharedContent.pm to communicate with Mana-KB 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-KB - create datatable in mana-subscription-search-result.inc to show results from a research on Mana-KB - 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 the language of the share and to alert if the subscription is already link to a Mana-KB 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-KB - modify subscription-add.tt and subscription.pl to manage a import from Mana-KB during a subscription creation - add 2 script in svc for ajax calling from subscription-add.tt to communicate with Mana-KB server during a asubscription creation - add a function in Subscription.pm to have all the info for a Mana-KB research from a biblionumber - modify functions used by subscription-add.pl in C4/Serials to manage a frequency which came from Mana-KB server and not already created on the koha database, and modify the tests of the said functions --- C4/Serials.pm | 39 +-- Koha/Subscription.pm | 66 +++++ .../prog/en/includes/serials-menu.inc | 3 + .../prog/en/includes/serials-toolbar.inc | 108 +++++++ .../prog/en/modules/serials/serials-home.tt | 1 + .../prog/en/modules/serials/serials-search.tt | 49 +++- .../prog/en/modules/serials/subscription-add.tt | 217 ++++++++++++-- .../prog/en/modules/serials/subscription-detail.tt | 16 +- misc/cronjobs/serialsUpdate.pl | 4 +- serials/serials-collection.pl | 6 +- serials/serials-search.pl | 122 +++++--- serials/showpredictionpattern.pl | 23 +- serials/subscription-add.pl | 81 +++++- serials/subscription-detail.pl | 71 ++++- t/db_dependent/Serials.t | 3 +- t/db_dependent/Serials/GetFictiveIssueNumber.t | 319 ++++++++------------- t/db_dependent/Serials/GetNextDate.t | 308 +++++++++----------- t/db_dependent/Serials/GetNextSeq.t | 124 ++++---- 18 files changed, 1009 insertions(+), 551 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 177bc76..e81831e 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -871,19 +871,20 @@ sub GetDistributedTo { my ( $nextseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 - ) = GetNextSeq( $subscription, $pattern, $planneddate ); + ) = GetNextSeq( $subscription, $pattern, $frequency, $planneddate ); $subscription is a hashref containing all the attributes of the table 'subscription'. $pattern is a hashref containing all the attributes of the table 'subscription_numberpatterns'. +$frequency is a hashref containing all the attributes of the table 'subscription_frequencies' $planneddate is a date string in iso format. This function get the next issue for the subscription given on input arg =cut sub GetNextSeq { - my ($subscription, $pattern, $planneddate) = @_; + my ($subscription, $pattern, $frequency, $planneddate) = @_; return unless ($subscription and $pattern); @@ -896,7 +897,7 @@ sub GetNextSeq { if(@irreg > 0) { my $irregularities = {}; $irregularities->{$_} = 1 foreach(@irreg); - my $issueno = GetFictiveIssueNumber($subscription, $planneddate) + 1; + my $issueno = GetFictiveIssueNumber($subscription, $planneddate, $frequency) + 1; while($irregularities->{$issueno}) { $count++; $issueno++; @@ -1039,7 +1040,7 @@ sub GetExpirationDate { #calculate the date of the last issue. for ( my $i = 1 ; $i <= $length ; $i++ ) { - $enddate = GetNextDate( $subscription, $enddate ); + $enddate = GetNextDate( $subscription, $enddate, $frequency ); } } elsif ( $subscription->{monthlength} ) { if ( $$subscription{startdate} ) { @@ -1191,16 +1192,17 @@ sub ModSerialStatus { if ( !$otherIssueExpected && $oldstatus == EXPECTED && $status != EXPECTED ) { my $subscription = GetSubscription($subscriptionid); my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); + my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); # next issue number my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ) - = GetNextSeq( $subscription, $pattern, $publisheddate ); + = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate ); # next date (calculated from actual date & frequency parameters) - my $nextpublisheddate = GetNextDate($subscription, $publisheddate, 1); + my $nextpublisheddate = GetNextDate($subscription, $publisheddate, $frequency, 1); my $nextpubdate = $nextpublisheddate; $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? WHERE subscriptionid = ?"; @@ -1409,7 +1411,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; @@ -1423,8 +1425,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( @@ -1435,7 +1437,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'}; @@ -2193,7 +2195,7 @@ sub abouttoexpire { my $expirationdate = GetExpirationDate($subscriptionid); my ($res) = $dbh->selectrow_array('select max(planneddate) from serial where subscriptionid = ?', undef, $subscriptionid); - my $nextdate = GetNextDate($subscription, $res); + my $nextdate = GetNextDate($subscription, $res, $frequency); # only compare dates if both dates exist. if ($nextdate and $expirationdate) { @@ -2259,7 +2261,7 @@ sub GetSubscriptionsFromBorrower { =head2 GetFictiveIssueNumber -$issueno = GetFictiveIssueNumber($subscription, $publishedate); +$issueno = GetFictiveIssueNumber($subscription, $publishedate, $frequency); Get the position of the issue published at $publisheddate, considering the first issue (at firstacquidate) is at position 1, the next is at position 2, etc... @@ -2278,9 +2280,8 @@ date (in GetNextDate) or the next issue number (in GetNextSeq). =cut sub GetFictiveIssueNumber { - my ($subscription, $publisheddate) = @_; + my ($subscription, $publisheddate, $frequency) = @_; - my $frequency = GetSubscriptionFrequency($subscription->{'periodicity'}); my $unit = $frequency->{unit} ? lc $frequency->{'unit'} : undef; return if !$unit; my $issueno; @@ -2424,12 +2425,13 @@ sub _get_next_date_year { =head2 GetNextDate -$resultdate = GetNextDate($publisheddate,$subscription) +$resultdate = GetNextDate($publisheddate,$subscription,$freqdata,$updatecount) this function it takes the publisheddate and will return the next issue's date and will skip dates if there exists an irregularity. $publisheddate has to be an ISO date -$subscription is a hashref containing at least 'periodicity', 'firstacquidate', 'irregularity', and 'countissuesperunit' +$subscription is a hashref containing at least 'firstacquidate', 'irregularity', and 'countissuesperunit' +$frequency is a hashref containing frequency informations $updatecount is a boolean value which, when set to true, update the 'countissuesperunit' in database - eg if periodicity is monthly and $publisheddate is 2007-02-10 but if March and April is to be skipped then the returned date will be 2007-05-10 @@ -2442,11 +2444,10 @@ Return undef if subscription is irregular =cut sub GetNextDate { - my ( $subscription, $publisheddate, $updatecount ) = @_; + my ( $subscription, $publisheddate, $freqdata, $updatecount ) = @_; return unless $subscription and $publisheddate; - my $freqdata = GetSubscriptionFrequency($subscription->{'periodicity'}); if ($freqdata->{'unit'}) { my ( $year, $month, $day ) = split /-/, $publisheddate; @@ -2466,7 +2467,7 @@ sub GetNextDate { # Get the 'fictive' next issue number # It is used to check if next issue is an irregular issue. - my $issueno = GetFictiveIssueNumber($subscription, $publisheddate) + 1; + my $issueno = GetFictiveIssueNumber($subscription, $publisheddate, $freqdata) + 1; # Then get the next date my $unit = lc $freqdata->{'unit'}; diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm index 332a018..40943dd 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,66 @@ Koha::Subscription - Koha Subscription Object class =cut +sub get_search_info { + my $searched_sub_id = shift; + my $biblio = Koha::Biblios->find( { 'biblionumber' => $searched_sub_id } ); + my $biblioitem = + Koha::Biblioitems->find( { 'biblionumber' => $searched_sub_id } ); + + my $sub_mana_info = { + 'title' => $biblio->title, + 'issn' => $biblioitem->issn, + 'ean' => $biblioitem->ean, + 'publishercode' => $biblioitem->publishercode + }; + return $sub_mana_info; +} + +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/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/includes/serials-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc index ecc9e55..2cebb6d 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/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/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt index ff918b0..46c732e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -1,5 +1,6 @@ [% USE KohaDates %] [% USE Branches %] +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] Koha › Serials › [% IF ( modify ) %][% bibliotitle |html %] › Modify subscription[% ELSE %]New subscription[% END %] @@ -11,11 +12,16 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ width: 300px; /* not enough for IE7 apparently */ } + +[% INCLUDE 'datatables.inc' %]