From 2d7fd8c09265880bf7ec548877569d698d14cdbb 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: Martin Renvoize Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- Koha/Template/Plugin/Desks.pm | 80 ++++--------------- .../prog/en/includes/circ-nav.inc | 2 +- .../intranet-tmpl/prog/en/includes/header.inc | 6 +- .../prog/en/modules/circ/circulation-home.tt | 2 +- .../prog/en/modules/circ/set-library.tt | 1 + 5 files changed, 22 insertions(+), 69 deletions(-) diff --git a/Koha/Template/Plugin/Desks.pm b/Koha/Template/Plugin/Desks.pm index a3be8c365f..27d0297081 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 ListForLibrary -[% Desks.all %] +[% Desks.ListForLibrary %] 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 ListForLibrary { + 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..574224cdd6 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.ListForLibrary.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 152483c94f..67e0a96fb4 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.ListForLibrary.count %] | [% IF ( Desks.GetLoggedInDeskName == '' ) %] @@ -119,7 +119,7 @@
  • Desk:
    - [% IF ( Desks.GetLoggedInDeskName == '' AND Desks.defined ) %] + [% IF ( Desks.GetLoggedInDeskName == '' AND Desks.ListForLibrary.count ) %] NO DESK SET [% ELSIF ( Desks.GetLoggedInDeskName != '' ) %] [% Desks.GetLoggedInDeskName | html %] @@ -139,7 +139,7 @@ Set library
  • [% END %] - [% IF Desks.defined %] + [% IF Desks.ListForLibrary.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..caf7f3db52 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.ListForLibrary.count %]
  • Set desk
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt index 14784e7d98..4a5ac05534 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt @@ -63,6 +63,7 @@ Updated:
    • [% END %] -- 2.39.5