Bugzilla – Attachment 106357 Details for
Bug 25765
Replace LoginBranchname and LoginBranchcode with use of Branches template plugin
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25765: Add GetLoggedInBranchname method
Bug-25765-Add-GetLoggedInBranchname-method.patch (text/plain), 3.28 KB, created by
Victor Grousset/tuxayo
on 2020-06-27 23:00:50 UTC
(
hide
)
Description:
Bug 25765: Add GetLoggedInBranchname method
Filename:
MIME Type:
Creator:
Victor Grousset/tuxayo
Created:
2020-06-27 23:00:50 UTC
Size:
3.28 KB
patch
obsolete
>From 17feace292d148558d9de384b674fcd13ccfeed7 Mon Sep 17 00:00:00 2001 >From: Fridolin Somers <fridolin.somers@biblibre.com> >Date: Tue, 16 Jun 2020 13:59:29 +0200 >Subject: [PATCH] Bug 25765: Add GetLoggedInBranchname method > >Add GetLoggedInBranchname method to Branches templates plugin. > >Also changes GetName method to use Koha::Library instead of direct SQL. > >Test plan : >Run prove t/db_dependent/Template/Plugin/Branches.t > >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >--- > Koha/Template/Plugin/Branches.pm | 18 ++++++++++-------- > t/db_dependent/Template/Plugin/Branches.t | 11 ++++++----- > 2 files changed, 16 insertions(+), 13 deletions(-) > >diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm >index e5c8bdc9b5..51a2df93a3 100644 >--- a/Koha/Template/Plugin/Branches.pm >+++ b/Koha/Template/Plugin/Branches.pm >@@ -30,19 +30,21 @@ use Koha::Libraries; > 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 { >diff --git a/t/db_dependent/Template/Plugin/Branches.t b/t/db_dependent/Template/Plugin/Branches.t >index b75b37632b..17a41b7fe6 100644 >--- a/t/db_dependent/Template/Plugin/Branches.t >+++ b/t/db_dependent/Template/Plugin/Branches.t >@@ -38,7 +38,7 @@ my $builder = t::lib::TestBuilder->new; > > subtest 'all() tests' => sub { > >- plan tests => 16; >+ plan tests => 18; > > $schema->storage->txn_begin; > >@@ -46,6 +46,7 @@ subtest 'all() tests' => sub { > source => 'Branch', > value => { > branchcode => 'MYLIBRARY', >+ branchname => 'My sweet library' > } > }); > my $another_library = $builder->build({ >@@ -67,12 +68,12 @@ subtest 'all() tests' => sub { > $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(); >-- >2.27.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 25765
:
105909
|
105910
|
106357
|
106358
|
107154
|
107155
|
107156
|
107157