From 047a78c1b42ecbea3b23515b434343314cbc184c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 15 Nov 2016 10:17:22 +0000 Subject: [PATCH] Bug 17627: Move C4::Koha::GetItemTypesByCategory to Koha::ItemTypes C4::Koha::GetItemTypesByCategory can be easily replaced with Koha::ItemTypes->search({ searchcategory => ? }); So let's replace it where it is used. Test plan: Make sure this patch does not break the test plan of bug 10937 Signed-off-by: Nick Clemens --- C4/Koha.pm | 20 +------------------- opac/opac-search.pl | 3 ++- t/db_dependent/Koha.t | 15 ++++++++------- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index b6e494a..2884267 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -42,7 +42,7 @@ BEGIN { @EXPORT = qw( &GetPrinters &GetPrinter &GetItemTypes &getitemtypeinfo - &GetItemTypesCategorized &GetItemTypesByCategory + &GetItemTypesCategorized &getallthemes &getFacets &getnbpages @@ -207,24 +207,6 @@ sub GetItemTypesCategorized { return ($dbh->selectall_hashref($query,'itemtype')); } -=head2 GetItemTypesByCategory - - @results = GetItemTypesByCategory( $searchcategory ); - -Returns the itemtype code of all itemtypes included in a searchcategory. - -=cut - -sub GetItemTypesByCategory { - my ($category) = @_; - my $count = 0; - my @results; - my $dbh = C4::Context->dbh; - my $query = qq|SELECT itemtype FROM itemtypes WHERE searchcategory=?|; - my $tmp=$dbh->selectcol_arrayref($query,undef,$category); - return @$tmp; -} - =head2 getitemtypeinfo $itemtype = &getitemtypeinfo($itemtype, [$interface]); diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 15e24b3..a84e9d3 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -479,7 +479,8 @@ my %is_nolimit = map { $_ => 1 } @nolimits; if (@searchCategories > 0) { my @tabcat; foreach my $typecategory (@searchCategories) { - push (@tabcat, GetItemTypesByCategory($typecategory)); + my @itemtypes = Koha::ItemTypes->search({ searchcategory => $typecategory }); + push @tabcat, $_->itemtype for @itemtypes; } foreach my $itemtypeInCategory (@tabcat) { diff --git a/t/db_dependent/Koha.t b/t/db_dependent/Koha.t index 3d5e203..feb4a1c 100644 --- a/t/db_dependent/Koha.t +++ b/t/db_dependent/Koha.t @@ -13,7 +13,7 @@ use Test::More tests => 8; use DateTime::Format::MySQL; BEGIN { - use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote GetItemTypesByCategory GetItemTypesCategorized)); + use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote GetItemTypesCategorized)); use_ok('C4::Members'); } @@ -239,7 +239,7 @@ subtest 'ISBN tests' => sub { }; -subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{ +subtest 'GetItemTypesCategorized test' => sub{ plan tests => 7; my $avc = Koha::AuthorisedValueCategories->find('ITEMTYPECAT'); @@ -259,12 +259,13 @@ subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{ $insertSth->execute('BKghjklo3', 'Yet another type of book', 'Qwertyware', 0); # Azertyware should not exist. - my @results = GetItemTypesByCategory('Azertyware'); - is(scalar @results, 0, 'GetItemTypesByCategory: Invalid category returns nothing'); + my @itemtypes = Koha::ItemTypes->search({ searchcategory => 'Azertyware' }); + is( @itemtypes, 0, 'Search item types by searchcategory: Invalid category returns nothing'); - @results = GetItemTypesByCategory('Qwertyware'); + @itemtypes = Koha::ItemTypes->search({ searchcategory => 'Qwertyware' }); + my @got = map { $_->itemtype } @itemtypes; my @expected = ( 'BKghjklo2', 'BKghjklo3' ); - is_deeply(\@results,\@expected,'GetItemTypesByCategory: valid category returns itemtypes'); + is_deeply(\@got,\@expected,'Search item types by searchcategory: valid category returns itemtypes'); # add more data since GetItemTypesCategorized's search is more subtle $insertGroup = Koha::AuthorisedValue->new( @@ -285,7 +286,7 @@ subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{ ok(exists $hrCat->{Qwertyware}, 'GetItemTypesCategorized: partially visible category exists'); my @only = ( 'BKghjklo1', 'BKghjklo2', 'BKghjklo3', 'BKghjklo4', 'BKghjklo5', 'Qwertyware', 'Veryheavybook' ); - @results = (); + my @results = (); foreach my $key (@only) { push @results, $key if exists $hrCat->{$key}; } -- 2.1.4