From f1860bcc8e8c2d199bbf97b240d6d0e5c9f5cfbe Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 26 Mar 2020 14:49:27 +0000 Subject: [PATCH] Bug 24201: (follow-up) Rework Desks Plugin This patch removes unused plugin methods (they can be re-introduced in subsequent bugs where they are used) and merges the 'all' and 'defined' methods into a ListForBranch method that returns a list of desks associated with the logged in branch. Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Andrew Fuerste-Henry --- Koha/Template/Plugin/Desks.pm | 80 +++++----------------- .../intranet-tmpl/prog/en/includes/circ-nav.inc | 2 +- .../intranet-tmpl/prog/en/includes/header.inc | 6 +- .../prog/en/modules/circ/circulation-home.tt | 2 +- 4 files changed, 21 insertions(+), 69 deletions(-) diff --git a/Koha/Template/Plugin/Desks.pm b/Koha/Template/Plugin/Desks.pm index a3be8c365f..5305b93a52 100644 --- a/Koha/Template/Plugin/Desks.pm +++ b/Koha/Template/Plugin/Desks.pm @@ -37,20 +37,6 @@ got or the current one. =head2 Methods -=head3 GetName - -[% Desk.GetName(desk_id) %] - -return desk name or empty string - -=cut - -sub GetName { - my ( $self, $desk_id ) = @_; - my $d = Koha::Desks->search( { desk_id => $desk_id} )->unblessed; - return @$d ? $d->{'desk_name'} : q{}; -} - =head3 GetLoggedInDeskId [% Desks.GetLoggedInDeskId %] @@ -62,9 +48,9 @@ return the desk name that is attached to the session or empty string sub GetLoggedInDeskId { my ($self) = @_; - return C4::Context->userenv ? - C4::Context->userenv->{'desk_id'} : - ''; + return C4::Context->userenv + ? C4::Context->userenv->{'desk_id'} + : ''; } =head3 GetLoggedInDeskName @@ -78,61 +64,27 @@ Return the desk name that is attached to the session or empty string sub GetLoggedInDeskName { my ($self) = @_; - return C4::Context->userenv ? - C4::Context->userenv->{'desk_name'} : - ''; + return C4::Context->userenv + ? C4::Context->userenv->{'desk_name'} + : ''; } -=head3 all +=head3 ListForBranch -[% Desks.all %] +[% Desks.ListForBranch %] returns all desks existing at the library =cut -sub all { - my ( $self, $params ) = @_; - my $selected = $params->{selected}; - my $unfiltered = $params->{unfiltered} || 0; - my $search_params = $params->{search_params} || {}; - - if ( !$unfiltered ) { - $search_params->{only_from_group} = $params->{only_from_group} || 0; - } - - my $desks = $unfiltered - ? Koha::Desks->search( $search_params, { order_by => ['desk_name'] } )->unblessed - : Koha::Desks->search_filtered( $search_params, { order_by => ['desk_name'] } )->unblessed; - - for my $d ( @$desks ) { - if ( defined $selected and $d->{desk_id} eq $selected - or not defined $selected and C4::Context->userenv and $d->{branchcode} eq ( C4::Context->userenv->{desk_id} // q{} ) - ) { - $d->{selected} = 1; - } - } - - return $desks; -} - -=head3 defined - -[% Desks.defined %] - -return 1 if there is at least a desk defined for the library. - -=cut - -sub defined { - my ( $self ) = @_; - my $desks = Koha::Desks->search()->unblessed; - if (@$desks) { - return 1 ; - } - else { - return 0; - } +sub ListForBranch { + my ($self) = @_; + my $branch_limit = + C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; + return scalar Koha::Desks->search( + { branchcode => $branch_limit }, + { order_by => { '-asc' => 'desk_name' } } + ); } 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc index 7360e1f288..2ffaf02328 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc @@ -18,7 +18,7 @@ [% IF ( AutoLocation ) %][% ELSE %][% IF ( IndependentBranches ) %][% ELSE %]
  • Set library
  • [% END %][% END %] - [% IF ( Desks.defined ) %] + [% IF Desks.ListForBranch.count %]
  • Set desk
  • [% END %] [% IF ( fast_cataloging ) %][% IF ( CAN_user_editcatalogue_fast_cataloging ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc index 37b16132c8..f4e94dcb22 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc @@ -86,7 +86,7 @@ [% Branches.GetLoggedInBranchcode | html %] [% END %] - [% IF (Desks.defined) %] + [% IF Desks.ListForBranch.count %] | [% IF ( Desks.GetLoggedInDeskName == '' ) %] @@ -119,7 +119,7 @@
  • Desk:
    - [% IF ( Desks.GetLoggedInDeskName == '' AND Desks.defined ) %] + [% IF ( Desks.GetLoggedInDeskName == '' AND Desks.ListForBranch.count ) %] NO DESK SET [% ELSIF ( Desks.GetLoggedInDeskName != '' ) %] [% Desks.GetLoggedInDeskName | html %] @@ -139,7 +139,7 @@ Set library
  • [% END %] - [% IF Desks.defined %] + [% IF Desks.ListForBranch.count %]
  • Set desk
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt index 5c17f284f9..f6490a47c6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt @@ -34,7 +34,7 @@ Set library [% END %] - [% IF Desks.defined %] + [% IF Desks.ListForBranch.count %]
  • Set desk
  • -- 2.11.0