From 42f0bec51b1acc81476f1eaa678bf82761f9f70e Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Tue, 7 Nov 2017 13:51:45 -0500 Subject: [PATCH] Bug 17674 - Move subroutine GetSerialItemsInformations to Koha/Serials.pm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Séverine QUEUNE --- C4/Serials.pm | 24 --------------- Koha/Serials.pm | 35 ++++++++++++++++++++++ .../prog/en/modules/serials/serials-collection.tt | 20 +++++-------- serials/serials-collection.pl | 1 + t/db_dependent/Serials.t | 17 +++++------ 5 files changed, 52 insertions(+), 45 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 2418b26..ac21dad 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -87,7 +87,6 @@ BEGIN { HasItems &GetSubscriptionsFromBorrower &subscriptionCurrentlyOnOrder - &GetSerialItemsInformations ); } @@ -2725,29 +2724,6 @@ sub _can_do_on_subscription { return 0; } -=head1 GetSerialItemsInformations - - @serialsitemsinformations = GetSerialItemsInformations (@serialid) - - return an array of specifique information of serials and serialitem a given array of serialid - -=cut - -sub GetSerialItemsInformations{ - my (@serialid)=@_; - my @serialitemsinformation; - my $dbh = C4::Context->dbh; - foreach my $sid(@serialid){ - my $sth = $dbh->prepare("select count(i.itemnumber) as countitems,s.itemnumber as itemnumber from items i natural join serialitems s where s.serialid=?"); - $sth->execute($sid); - my $line = $sth->fetchrow_hashref; - if($line->{'countitems'}){ - push @serialitemsinformation,$line; - } - } - return @serialitemsinformation; -} - =head2 findSerialsByStatus @serials = findSerialsByStatus($status, $subscriptionid); diff --git a/Koha/Serials.pm b/Koha/Serials.pm index e970448..e5ba33c 100644 --- a/Koha/Serials.pm +++ b/Koha/Serials.pm @@ -27,6 +27,16 @@ use Koha::Serial; use base qw(Koha::Objects); +use vars qw(@ISA @EXPORT); + +BEGIN { + require Exporter; + @ISA = qw(Exporter); + @EXPORT = qw( + &GetSerialItemsInformations + ); +} + =head1 NAME Koha::Serial - Koha Serial Object class @@ -49,6 +59,31 @@ sub object_class { return 'Koha::Serial'; } +=head2 GetSerialItemsInformations + + @serialsitemsinformations = GetSerialItemsInformations (@serialid) + + return an array of specifique information of serials and serialitem a given array of serialid + +=cut + +sub GetSerialItemsInformations{ + my ( @serialid ) = @_; + my @serialitemsinformation; + my $dbh = C4::Context->dbh; + + foreach my $sid ( @serialid ) { + my $sth = $dbh->prepare("select count(i.itemnumber) as countitems,s.itemnumber as itemnumber from items i natural join serialitems s where s.serialid=?"); + $sth->execute( $sid ); + + my $line = $sth->fetchrow_hashref; + if( $line->{'countitems'} ){ + push @serialitemsinformation, $line; + } + } + return @serialitemsinformation; +} + =head1 AUTHOR Kyle M Hall diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt index e0bec41..7baa2fb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt @@ -27,7 +27,7 @@ -
+
@@ -180,18 +180,14 @@ [% IF ( serial.subscriptionexpired ) %] [% ELSE %] - [% IF ( serial.checked ) %] - [% IF ( delete ) %] - - [% ELSE %] - - [% END %] + [% IF ( delete ) %] + [% IF serialsid.grep("${serial.serialid}").size %] + + [% ELSE %] + + [% END %] [% ELSE %] - [% IF ( delete ) %] - - [% ELSE %] - - [% END %] + [% END %] [% END %] [% END %] diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl index 475790c..4dfbe38 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -28,6 +28,7 @@ use C4::Items; use C4::Letters; use C4::Output; use C4::Context; +use Koha::Serials; use List::MoreUtils qw/uniq/; diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t index 201bc6f..d5f4996 100755 --- a/t/db_dependent/Serials.t +++ b/t/db_dependent/Serials.t @@ -16,6 +16,7 @@ use C4::Budgets; use C4::Items; use Koha::DateUtils; use Koha::Acquisition::Booksellers; +use Koha::Serials; use t::lib::Mocks; use Test::More tests => 50; use t::lib::TestBuilder; @@ -31,8 +32,6 @@ my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; -my $builder = t::lib::TestBuilder->new(); - # This could/should be used for all untested methods my @methods = ('updateClaim'); can_ok('C4::Serials', @methods); @@ -375,25 +374,25 @@ subtest "Test GetSerialItemsInformations " => sub { AddItem2Serial($serialid[0],$itemnumber1); my @result = C4::Serials::GetSerialItemsInformations(@serialid); is (scalar @result, 1 , "GetSerialItemsInformation return right length of array using 1 serial with 1 item"); - is (@result[0]->{countitems}, 1 , "GetSerialItemsInformation return right number items of serial1"); + is ($result[0]->{countitems}, 1 , "GetSerialItemsInformation return right number items of serial1"); AddItem2Serial($serialid[1],$itemnumber3); @result = C4::Serials::GetSerialItemsInformations(@serialid); is (scalar @result, 2 , "GetSerialItemsInformation return right length of array using 2 serials and each have 1 item"); - is (@result[0]->{countitems}, 1 , "GetSerialItemsInformation return right number items of serial1"); - is (@result[1]->{countitems}, 1 , "GetSerialItemsInformation return right number items of serial2"); + is ($result[0]->{countitems}, 1 , "GetSerialItemsInformation return right number items of serial1"); + is ($result[1]->{countitems}, 1 , "GetSerialItemsInformation return right number items of serial2"); }; subtest "Test with 2 serials and each have 2 items" => sub { plan tests => 6; AddItem2Serial($serialid[0],$itemnumber2); my @result = C4::Serials::GetSerialItemsInformations(@serialid); is (scalar @result, 2 , "GetSerialItemsInformation return right length of array using 2 serials "); - is (@result[0]->{countitems}, 2 , "GetSerialItemsInformation return right number items of serial1"); - is (@result[1]->{countitems}, 1 , "GetSerialItemsInformation return right number items of serial2"); + is ($result[0]->{countitems}, 2 , "GetSerialItemsInformation return right number items of serial1"); + is ($result[1]->{countitems}, 1 , "GetSerialItemsInformation return right number items of serial2"); AddItem2Serial($serialid[1],$itemnumber4); @result = C4::Serials::GetSerialItemsInformations(@serialid); is (scalar @result, 2 , "GetSerialItemsInformation return right length of array using 2 serials and each have 2 items "); - is (@result[0]->{countitems}, 2 , "GetSerialItemsInformation return right number items of serial1"); - is (@result[1]->{countitems}, 2 , "GetSerialItemsInformation return right number items of serial2"); + is ($result[0]->{countitems}, 2 , "GetSerialItemsInformation return right number items of serial1"); + is ($result[1]->{countitems}, 2 , "GetSerialItemsInformation return right number items of serial2"); }; }; -- 2.1.4