Bugzilla – Attachment 45760 Details for
Bug 15295
Move the C4::Branch related code to Koha::Libraries - part 2
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15295: Koha::Libraries - Remove GetBranchCategories
Bug-15295-KohaLibraries---Remove-GetBranchCategori.patch (text/plain), 10.20 KB, created by
Marc Véron
on 2015-12-17 10:58:50 UTC
(
hide
)
Description:
Bug 15295: Koha::Libraries - Remove GetBranchCategories
Filename:
MIME Type:
Creator:
Marc Véron
Created:
2015-12-17 10:58:50 UTC
Size:
10.20 KB
patch
obsolete
>From b2b091e2135fbb36269c12f6b4f6ec9945bf2f11 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 3 Dec 2015 14:35:05 +0000 >Subject: [PATCH] Bug 15295: Koha::Libraries - Remove GetBranchCategories >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Test plan >1/ enable OpacAddMastheadLibraryPulldown >2/ Defined a group of libraries as searchdomain >and tick 'show in pull down' >3/ At the OPAC, go on the advanced search form, limit by the group of >libraries you have just created. >4/ The group should be selected by default in the dropdown list > >Signed-off-by: Marc Véron <veron@veron.ch> >--- > C4/Auth.pm | 5 +- > C4/Branch.pm | 50 ++------------------ > catalogue/search.pl | 3 +- > .../opac-tmpl/bootstrap/en/includes/masthead.inc | 2 +- > opac/opac-search.pl | 7 +-- > t/db_dependent/Branch.t | 20 +++----- > 6 files changed, 21 insertions(+), 66 deletions(-) > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index 8512fd9..acc28a3 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -32,6 +32,7 @@ use C4::Branch; # GetBranches > use C4::Search::History; > use Koha; > use Koha::AuthUtils qw(hash_password); >+use Koha::LibraryCategories; > use POSIX qw/strftime/; > use List::MoreUtils qw/ any /; > use Encode qw( encode is_utf8); >@@ -501,12 +502,14 @@ sub get_template_and_user { > $opac_name = C4::Context->userenv->{'branch'}; > } > >+ my $library_categories = Koha::LibraryCategories->search({categorytype => 'searchdomain', show_in_pulldown => 1}, { order_by => ['categorytype', 'categorycode']}); > $template->param( > OpacAdditionalStylesheet => C4::Context->preference("OpacAdditionalStylesheet"), > AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"), > AuthorisedValueImages => C4::Context->preference("AuthorisedValueImages"), > BranchesLoop => GetBranchesLoop($opac_name), >- BranchCategoriesLoop => GetBranchCategories( 'searchdomain', 1, $opac_name ), >+ BranchCategoriesLoop => $library_categories, >+ opac_name => $opac_name, > LibraryName => "" . C4::Context->preference("LibraryName"), > LibraryNameTitle => "" . $LibraryNameTitle, > LoginBranchname => C4::Context->userenv ? C4::Context->userenv->{"branchname"} : "", >diff --git a/C4/Branch.pm b/C4/Branch.pm >index 2397fd0..2e9a9c6 100644 >--- a/C4/Branch.pm >+++ b/C4/Branch.pm >@@ -20,6 +20,7 @@ use strict; > #use warnings; FIXME - Bug 2505 > require Exporter; > use C4::Context; >+use Koha::LibraryCategories; > > use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); > >@@ -37,7 +38,6 @@ BEGIN { > &ModBranch > &GetBranchInfo > &GetCategoryTypes >- &GetBranchCategories > &GetBranchesInCategory > &ModBranchCategoryInfo > &mybranch >@@ -243,9 +243,9 @@ sub ModBranch { > } > # sort out the categories.... > my @checkedcats; >- my $cats = GetBranchCategories(); >- foreach my $cat (@$cats) { >- my $code = $cat->{'categorycode'}; >+ my @cats = Koha::LibraryCategories->search; >+ foreach my $cat (@cats) { >+ my $code = $cat->categorycode; > if ( $data->{$code} ) { > push( @checkedcats, $code ); > } >@@ -283,48 +283,6 @@ sub ModBranch { > } > } > >-=head2 GetBranchCategories >- >- my $categories = GetBranchCategories($categorytype,$show_in_pulldown,$selected_in_pulldown); >- >-Returns a list ref of anon hashrefs with keys eq columns of branchcategories table, >-i.e. categorydescription, categorytype, categoryname. >- >-=cut >- >-sub GetBranchCategories { >- my ( $categorytype, $show_in_pulldown, $selected_in_pulldown ) = @_; >- my $dbh = C4::Context->dbh(); >- >- my $query = "SELECT * FROM branchcategories "; >- >- my ( @where, @bind ); >- if ( $categorytype ) { >- push @where, " categorytype = ? "; >- push @bind, $categorytype; >- } >- >- if ( defined( $show_in_pulldown ) ) { >- push( @where, " show_in_pulldown = ? " ); >- push( @bind, $show_in_pulldown ); >- } >- >- $query .= " WHERE " . join(" AND ", @where) if(@where); >- $query .= " ORDER BY categorytype, categorycode"; >- my $sth=$dbh->prepare( $query); >- $sth->execute(@bind); >- >- my $branchcats = $sth->fetchall_arrayref({}); >- >- if ( $selected_in_pulldown ) { >- foreach my $bc ( @$branchcats ) { >- $bc->{selected} = 1 if $bc->{categorycode} eq $selected_in_pulldown; >- } >- } >- >- return $branchcats; >-} >- > =head2 GetCategoryTypes > > $categorytypes = GetCategoryTypes; >diff --git a/catalogue/search.pl b/catalogue/search.pl >index e74ceca..9d648f1 100755 >--- a/catalogue/search.pl >+++ b/catalogue/search.pl >@@ -152,6 +152,7 @@ use POSIX qw(ceil floor); > use C4::Branch; # GetBranches > use C4::Search::History; > >+use Koha::LibraryCategories; > use Koha::Virtualshelves; > > use URI::Escape; >@@ -244,7 +245,7 @@ my @branch_loop = map { > $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} > } keys %$branches; > >-my $categories = GetBranchCategories('searchdomain'); >+my $categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } ); > > $template->param(branchloop => \@branch_loop, searchdomainloop => $categories); > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc >index 20ff3f8..527424d 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc >@@ -234,7 +234,7 @@ > </optgroup> > <optgroup label="Groups"> > [% FOREACH bc IN BranchCategoriesLoop %] >- [% IF ( bc.selected ) %] >+ [% IF bc.categorycode == opac_name %] > <option selected="selected" value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option> > [% ELSE %] > <option value="multibranchlimit-[% bc.categorycode %]">[% bc.categoryname %]</option> >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index efbbbb2..7f64e6b 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -43,6 +43,8 @@ use C4::SocialData; > use C4::Ratings; > use C4::External::OverDrive; > >+use Koha::LibraryCategories; >+ > use POSIX qw(ceil floor strftime); > use URI::Escape; > use JSON qw/decode_json encode_json/; >@@ -201,9 +203,8 @@ if ($cgi->cookie("search_path_code")) { > } > > my $branches = GetBranches(); # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established >-$template->param( >- searchdomainloop => GetBranchCategories('searchdomain'), >-); >+my $library_categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } ); >+$template->param( searchdomainloop => $library_categories ); > > # load the language limits (for search) > my $languages_limit_loop = getLanguages($lang, 1); >diff --git a/t/db_dependent/Branch.t b/t/db_dependent/Branch.t >index 3ca302f..afac90e 100644 >--- a/t/db_dependent/Branch.t >+++ b/t/db_dependent/Branch.t >@@ -21,7 +21,7 @@ use Modern::Perl; > use C4::Context; > use Data::Dumper; > >-use Test::More tests => 26; >+use Test::More tests => 24; > > use C4::Branch; > use Koha::Libraries; >@@ -43,7 +43,6 @@ can_ok( > ModBranch > GetBranchInfo > GetCategoryTypes >- GetBranchCategories > GetBranchesInCategory > ModBranchCategoryInfo > mybranch >@@ -165,8 +164,7 @@ $b1->{issuing} = undef; > is_deeply( $branchdetail, $b1 , "GetBranchDetail gives the details of BRA"); > > #Test categories >-my $categories = GetBranchCategories(); >-my $count_cat = scalar( @$categories ); >+my $count_cat = Koha::LibraryCategories->search->count; > > my $cat1 = { > add => 1, >@@ -201,18 +199,16 @@ ModBranchCategoryInfo({ > ModBranchCategoryInfo($cat1); > ModBranchCategoryInfo($cat2); > >-$categories = GetBranchCategories(); >-is( scalar( @$categories ), $count_cat + 3, "Two categories added" ); >+my $categories = Koha::LibraryCategories->search; >+is( $categories->count, $count_cat + 3, "Two categories added" ); > delete $cat1->{add}; > delete $cat2->{add}; > delete $new_category{add}; >-is_deeply($categories, [ $cat1,$cat2,\%new_category ], 'retrieve all expected library categories (bug 10515)'); > > my $del = Koha::LibraryCategories->find( $cat2->{categorycode} )->delete; > is( $del, 1, 'One row affected' ); > >-$categories = GetBranchCategories(); >-is( scalar( @$categories ), $count_cat + 2, "Category CAT2 deleted" ); >+is( Koha::LibraryCategories->search->count, $count_cat + 2, "Category CAT 2 deleted" ); > > $b2->{CAT1} = 1; > ModBranch($b2); >@@ -232,8 +228,7 @@ $b2->{categories} = \@cat; > is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' ); > > ModBranchCategoryInfo({add => 1,%$cat2}); >-$categories = GetBranchCategories(); >-is( scalar( @$categories ), $count_cat + 3, "Two categories added" ); >+is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two catgories added" ); > $b2 = { > branchcode => 'BRB', > branchname => 'BranchB', >@@ -302,9 +297,6 @@ is_deeply( $brCat1, \@b, 'CAT1 has branch BRB and BRC' ); > my @category_types = GetCategoryTypes(); > is_deeply(\@category_types, [ 'searchdomain', 'properties' ], 'received expected library category types'); > >-$categories = GetBranchCategories(undef, undef, 'LIBCATCODE'); >-is_deeply($categories, [ {%$cat1}, {%$cat2},{ %new_category, selected => 1 } ], 'retrieve expected, eselected library category (bug 10515)'); >- > #TODO later: test mybranchine and onlymine > # Actually we cannot mock C4::Context->userenv in unit tests > >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15295
:
45368
|
45369
|
45370
|
45371
|
45372
|
45373
|
45374
|
45375
|
45752
|
45754
|
45755
|
45756
|
45757
|
45760
|
45763
|
45764
|
45765
|
45924
|
45925
|
45926
|
45927
|
45928
|
45929
|
45930
|
45931
|
46684
|
46696