1 package Koha::Template::Plugin::Branches;
3 # Copyright ByWater Solutions 2012
4 # Copyright BibLibre 2014
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use base qw( Template::Plugin );
30 my ( $self, $branchcode ) = @_;
32 my $query = "SELECT branchname FROM branches WHERE branchcode = ?";
33 my $sth = C4::Context->dbh->prepare($query);
34 $sth->execute($branchcode);
35 my $b = $sth->fetchrow_hashref();
36 return $b ? $b->{'branchname'} : q{};
39 sub GetLoggedInBranchcode {
42 return C4::Context->userenv ?
43 C4::Context->userenv->{'branch'} :
48 my ( $self, $branchcode ) = @_;
50 my $query = "SELECT branchurl FROM branches WHERE branchcode = ?";
51 my $sth = C4::Context->dbh->prepare($query);
52 $sth->execute($branchcode);
53 my $b = $sth->fetchrow_hashref();
54 return $b->{branchurl};
58 return C4::Branch::onlymine;
62 my ( $self, $params ) = @_;
63 my $selected = $params->{selected};
64 my $dbh = C4::Context->dbh;
67 SELECT branchcode, branchname
70 if ( C4::Context->preference('IndependentBranches')
71 and C4::Context->userenv
72 && !C4::Context->IsSuperLibrarian()
73 and C4::Context->userenv->{branch} )
75 $query .= q| WHERE branchcode = ? |;
76 push @params, C4::Context->userenv->{branch};
78 my $libraries = $dbh->selectall_arrayref( $query, { Slice => {} }, @params );
80 for my $l ( @$libraries ) {
81 if ( $selected and $l->{branchcode} eq $selected
82 or not $selected and C4::Context->userenv and $l->{branchcode} eq C4::Context->userenv->{branch}