[Koha-patches] [PATCH] Add onlymine helper function.
Joe Atzberger
joe.atzberger at liblime.com
Wed May 20 21:39:03 CEST 2009
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.
---
C4/Branch.pm | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/C4/Branch.pm b/C4/Branch.pm
index 0f33491..73cd5fd 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) {
--
1.5.6.5
More information about the Koha-patches
mailing list