From d564d3732d95455b4626dfa8ca711cd658003c17 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 20 Jan 2016 13:22:48 +0000 Subject: [PATCH] Bug 15629: Koha::Libraries - Remove GetBranchInfo C4::Branch::GetBranchInfo was only used once in opac/opac-suggestions.pl The occurrence can easily be replaced by a call to Koha::Libraries->find Test plan: 1/ Create a suggestion for library A 2/ Enable OPACViewOthersSuggestions 3/ Use a patron from library B to see the suggestions 4/ The "Suggested for" value should be correctly filled with the library A name. Signed-off-by: Owen Leonard Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- C4/Branch.pm | 50 ---------------------------------------- opac/opac-suggestions.pl | 3 ++- t/db_dependent/Branch.t | 18 ++++----------- 3 files changed, 7 insertions(+), 64 deletions(-) diff --git a/C4/Branch.pm b/C4/Branch.pm index b8eb9ca772..9f8263826f 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -33,7 +33,6 @@ BEGIN { &GetBranch &GetBranches &GetBranchesLoop - &GetBranchInfo &mybranch ); @EXPORT_OK = qw( &onlymine &mybranch ); @@ -58,7 +57,6 @@ The functions in this module deal with branches. $branches = &GetBranches(); Returns informations about ALL branches, IndependentBranches Insensitive. -GetBranchInfo() returns the same information. Create a branch selector with the following code. @@ -185,54 +183,6 @@ sub GetBranch { return $branch; } -=head2 GetBranchInfo - -$results = GetBranchInfo($branchcode); - -returns C<$results>, a reference to an array of hashes containing branches. -if $branchcode, just this branch, with associated categories. -if ! $branchcode && $categorytype, all branches in the category. - -=cut - -sub GetBranchInfo { - my ($branchcode,$categorytype) = @_; - my $dbh = C4::Context->dbh; - my $sth; - - - if ($branchcode) { - $sth = - $dbh->prepare( - "Select * from branches where branchcode = ? order by branchcode"); - $sth->execute($branchcode); - } - else { - $sth = $dbh->prepare("Select * from branches order by branchcode"); - $sth->execute(); - } - my @results; - while ( my $data = $sth->fetchrow_hashref ) { - my @bind = ($data->{'branchcode'}); - my $query= "select r.categorycode from branchrelations r"; - $query .= ", branchcategories c " if($categorytype); - $query .= " where branchcode=? "; - if($categorytype) { - $query .= " and c.categorytype=? and r.categorycode=c.categorycode"; - push @bind, $categorytype; - } - my $nsth=$dbh->prepare($query); - $nsth->execute( @bind ); - my @cats = (); - while ( my ($cat) = $nsth->fetchrow_array ) { - push( @cats, $cat ); - } - $data->{'categories'} = \@cats; - push( @results, $data ); - } - return \@results; -} - 1; __END__ diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index 83b12f1d37..46a5f1b1b7 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -28,6 +28,7 @@ use C4::Output; use C4::Suggestions; use C4::Koha; use C4::Scrubber; +use Koha::Libraries; use Koha::DateUtils qw( dt_from_string ); @@ -149,7 +150,7 @@ if ( $op eq "delete_confirm" ) { print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else"); exit; } -map{ $_->{'branchcodesuggestedby'}=GetBranchInfo($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @$suggestions_loop; +map{ $_->{'branchcodesuggestedby'} = Koha::Libraries->find($_->{'branchcodesuggestedby'})->branchname} @$suggestions_loop; foreach my $suggestion(@$suggestions_loop) { if($suggestion->{'suggestedby'} == $borrowernumber) { diff --git a/t/db_dependent/Branch.t b/t/db_dependent/Branch.t index c715e9831b..e10abd3b7b 100644 --- a/t/db_dependent/Branch.t +++ b/t/db_dependent/Branch.t @@ -40,7 +40,6 @@ can_ok( GetBranch GetBranches GetBranchesLoop - GetBranchInfo mybranch ) ); @@ -192,18 +191,11 @@ my $CAT1 = Koha::LibraryCategories->find('CAT1'); $b2_stored->add_to_categories([$CAT1]); is( Koha::Libraries->search->count, $count + 2, 'BRB added' ); -#Test GetBranchInfo -my $b1info = GetBranchInfo( $b1->{branchcode} ); -$b1->{categories} = []; -is_deeply( @$b1info[0], $b1, 'BRA has no categories' ); - -my $b2info = GetBranchInfo( $b2->{branchcode} ); -my @cat = ( $cat1->{categorycode} ); -delete $b2->{add}; -delete $b2->{CAT1}; -$b2->{issuing} = undef; -$b2->{categories} = \@cat; -is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' ); +my $b1info = Koha::Libraries->find( $b1->{branchcode} ); +is_deeply( $b1info->categories->count, 0, 'BRA has no categories' ); + +my $b2info = Koha::Libraries->find( $b2->{branchcode} ); +is_deeply( $b2->categories->count, 1, 'BRB has the category CAT1' ); Koha::LibraryCategory->new($cat2)->store; is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" ); -- 2.39.5