Bug 24201: (follow-up) Rework Desks Plugin
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 26 Mar 2020 14:49:27 +0000 (14:49 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 7 Aug 2020 14:54:40 +0000 (16:54 +0200)
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 <andrew@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/Template/Plugin/Desks.pm
koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc
koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt

index a3be8c3..27d0297 100644 (file)
@@ -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;
index 7360e1f..574224c 100644 (file)
@@ -18,7 +18,7 @@
             [% IF ( AutoLocation ) %][% ELSE %][% IF ( IndependentBranches ) %][% ELSE %]
                 <li><a href="/cgi-bin/koha/circ/set-library.pl">Set library</a></li>
             [% END %][% END %]
-            [% IF ( Desks.defined ) %]
+            [% IF Desks.ListForLibrary.count %]
                 <li><a href="/cgi-bin/koha/circ/selectdesk.pl">Set desk</a></li>
             [% END %]
             [% IF ( fast_cataloging ) %][% IF ( CAN_user_editcatalogue_fast_cataloging ) %]
index 152483c..67e0a96 100644 (file)
@@ -86,7 +86,7 @@
                                 <span class="logged-in-branch-code content_hidden">[% Branches.GetLoggedInBranchcode | html %]</span>
                             </strong>
                         [% END %]
-                        [% IF (Desks.defined) %]
+                        [% IF Desks.ListForLibrary.count %]
                             <span class="separator">|</span>
                             <strong>
                                 [% IF ( Desks.GetLoggedInDeskName == '' ) %]
                     </li>
                     <li class="loggedin-menu-label">
                         Desk: <br />
-                        [% IF ( Desks.GetLoggedInDeskName == '' AND Desks.defined ) %]
+                        [% IF ( Desks.GetLoggedInDeskName == '' AND Desks.ListForLibrary.count ) %]
                            <span class="logged-in-desk-name">NO DESK SET</span>
                         [% ELSIF ( Desks.GetLoggedInDeskName != '' ) %]
                             <span class="logged-in-desk-name">[% Desks.GetLoggedInDeskName | html %]</span>
                         <a class="toplinks" href="/cgi-bin/koha/circ/set-library.pl">Set library</a>
                     </li>
                     [% END %]
-                    [% IF Desks.defined %]
+                    [% IF Desks.ListForLibrary.count %]
                     <li>
                         <a class="toplinks" href="/cgi-bin/koha/circ/selectdesk.pl">Set desk</a>
                     </li>
index 5c17f28..caf7f3d 100644 (file)
@@ -34,7 +34,7 @@
                             <a class="circ-button" href="/cgi-bin/koha/circ/set-library.pl"><i class="fa fa-home"></i> Set library</a>
                         </li>
                     [% END %]
-                    [% IF Desks.defined %]
+                    [% IF Desks.ListForLibrary.count %]
                         <li>
                             <a class="circ-button" href="/cgi-bin/koha/circ/selectdesk.pl"><i class="fa fa-location-arrow"></i> Set desk</a>
                         </li>
index 14784e7..4a5ac05 100644 (file)
@@ -63,6 +63,7 @@ Updated:<ul>
         <li><label for="branch">Choose library:</label>
         <select name="branch" id="branch">
             [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
+                        [% PROCESS options_for_yallah yallah => Branches.all( selected => branch ) %]
         </select></li>
     [% END %]
     </ol>