Bug 11826: (follow-up) enable printing warnings
[koha.git] / Koha / Template / Plugin / Branches.pm
index e201ff7..ff43a38 100644 (file)
@@ -24,6 +24,7 @@ use base qw( Template::Plugin );
 use Encode qw{encode decode};
 
 use C4::Koha;
+use C4::Context;
 
 sub GetName {
     my ( $self, $branchcode ) = @_;
@@ -32,7 +33,25 @@ sub GetName {
     my $sth   = C4::Context->dbh->prepare($query);
     $sth->execute($branchcode);
     my $b = $sth->fetchrow_hashref();
-    return encode('UTF-8', $b->{'branchname'});
+    return $b ? encode( 'UTF-8', $b->{'branchname'} ) : q{};
+}
+
+sub GetLoggedInBranchcode {
+    my ($self) = @_;
+
+    return C4::Context->userenv ?
+        C4::Context->userenv->{'branch'} :
+        '';
+}
+
+sub GetURL {
+    my ( $self, $branchcode ) = @_;
+
+    my $query = "SELECT branchurl FROM branches WHERE branchcode = ?";
+    my $sth   = C4::Context->dbh->prepare($query);
+    $sth->execute($branchcode);
+    my $b = $sth->fetchrow_hashref();
+    return encode( 'UTF-8', $b->{'branchurl'} );
 }
 
 1;