From 4f9d77ed3298b434336660cb15893b72a45ae234 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 20 May 2009 14:39:03 -0500 Subject: [PATCH] Add onlymine helper function. This should allow scripts to use GetBranchesLoop without having to reproduce the check for: (1) IndependantBranches, (2) User logged in, (3) User Not superlibrarian, and (4) User branch set. Signed-off-by: Galen Charlton --- C4/Branch.pm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/C4/Branch.pm b/C4/Branch.pm index 0f33491a98..73cd5fd229 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -25,7 +25,7 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); BEGIN { # set the version for version checking - $VERSION = 3.01; + $VERSION = 3.02; @ISA = qw(Exporter); @EXPORT = qw( &GetBranchCategory @@ -45,6 +45,7 @@ BEGIN { &DelBranch &DelBranchCategory ); + @EXPORT_OK = qw( &onlymine ); } =head1 NAME @@ -111,13 +112,14 @@ sub GetBranches { $query.=" ORDER BY branchname"; $sth = $dbh->prepare($query); $sth->execute( @bind_parameters ); + + my $nsth = $dbh->prepare( + "SELECT categorycode FROM branchrelations WHERE branchcode = ?" + ); # prepare once, outside while loop + while ( my $branch = $sth->fetchrow_hashref ) { - my $nsth = - $dbh->prepare( - "SELECT categorycode FROM branchrelations WHERE branchcode = ?"); $nsth->execute( $branch->{'branchcode'} ); while ( my ($cat) = $nsth->fetchrow_array ) { - # FIXME - This seems wrong. It ought to be # $branch->{categorycodes}{$cat} = 1; # otherwise, there's a namespace collision if there's a @@ -135,9 +137,17 @@ sub GetBranches { return ( \%branches ); } +sub onlymine { + return + C4::Context->preference('IndependantBranches') && + C4::Context->userenv && + C4::Context->userenv->{flags}!=1 && + C4::Context->userenv->{branch} ; +} + sub GetBranchesLoop (;$$) { # since this is what most pages want anyway my $branch = @_ ? shift : ''; # optional first argument is branchcode of "my branch", if preselection is wanted. - my $onlymine = @_ ? shift : C4::Context->preference("IndependantBranches"); + my $onlymine = @_ ? shift : onlymine(); my $branches = GetBranches($onlymine); my @loop; foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) { -- 2.39.5