sub GetName {
my ( $self, $branchcode ) = @_;
- my $query = "SELECT branchname FROM branches WHERE branchcode = ?";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute($branchcode);
- my $b = $sth->fetchrow_hashref();
- return $b ? $b->{'branchname'} : q{};
+ my $l = Koha::Libraries->find($branchcode);
+ return $l ? $l->branchname : q{};
}
sub GetLoggedInBranchcode {
my ($self) = @_;
- return C4::Context->userenv ?
- C4::Context->userenv->{'branch'} :
- '';
+ return C4::Context::mybranch;
+}
+
+sub GetLoggedInBranchname {
+ my ($self) = @_;
+
+ my $code = $self->GetLoggedInBranchcode;
+ return $code ? $self->GetName($code) : q{};
}
sub GetURL {
subtest 'all() tests' => sub {
- plan tests => 16;
+ plan tests => 18;
$schema->storage->txn_begin;
source => 'Branch',
value => {
branchcode => 'MYLIBRARY',
+ branchname => 'My sweet library'
}
});
my $another_library = $builder->build({
$name = $plugin->GetName(undef);
is($name, '', 'received empty string as name of NULL/undefined library code');
- $library = $plugin->GetLoggedInBranchcode();
- is($library, '', 'no active library if there is no active user session');
+ is($plugin->GetLoggedInBranchcode(), '', 'no active library code if there is no active user session');
+ is($plugin->GetLoggedInBranchname(), '', 'no active library name if there is no active user session');
t::lib::Mocks::mock_userenv({ branchcode => 'MYLIBRARY' });
- $library = $plugin->GetLoggedInBranchcode();
- is($library, 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library');
+ is($plugin->GetLoggedInBranchcode(), 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library code');
+ is($plugin->GetLoggedInBranchname(), 'My sweet library', 'GetLoggedInBranchname() returns active library name');
t::lib::Mocks::mock_preference( 'IndependentBranches', 0 );
my $libraries = $plugin->all();