Bug 24201: (QA follow-up) Do not unbless a list from search in Desks template plugin
[koha-equinox.git] / Koha / Template / Plugin / Desks.pm
1 package Koha::Template::Plugin::Desks;
2
3 # Copyright (C) BULAC 2020
4
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Template::Plugin;
23 use base qw( Template::Plugin );
24
25 use C4::Koha;
26 use C4::Context;
27 use Koha::Desks;
28
29 =head1 NAME
30
31 Koha::Template::Plugin::Desks - A module for dealing with desks in templates
32
33 =head1 DESCRIPTION
34
35 This plugin contains getters functions, to fetch all desks a library
36 got or the current one.
37
38 =head2 Methods
39
40 =head3 GetLoggedInDeskId
41
42 [% Desks.GetLoggedInDeskId %]
43
44 return the desk name that is attached to the session or empty string
45
46 =cut
47
48 sub GetLoggedInDeskId {
49     my ($self) = @_;
50
51     return C4::Context->userenv
52       ? C4::Context->userenv->{'desk_id'}
53       : '';
54 }
55
56 =head3 GetLoggedInDeskName
57
58 [% Desks.GetLoggedInDeskName %]
59
60 Return the desk name that is attached to the session or empty string
61
62 =cut
63
64 sub GetLoggedInDeskName {
65     my ($self) = @_;
66
67     return C4::Context->userenv
68       ? C4::Context->userenv->{'desk_name'}
69       : '';
70 }
71
72 =head3 ListForLibrary
73
74 [% Desks.ListForLibrary %]
75
76 returns all desks existing at the current library
77
78 =cut
79
80 sub ListForLibrary {
81     my ($self) = @_;
82     my $branch_limit =
83       C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
84     return scalar Koha::Desks->search(
85         { branchcode => $branch_limit },
86         { order_by   => { '-asc' => 'desk_name' } }
87     );
88 }
89
90 =head3 all
91
92 [% Desks.all %]
93
94 returns all desks existing at all libraries
95
96 =cut
97
98
99 sub all {
100
101     my ( $self ) = @_;
102     return Koha::Desks->search();
103 }
104
105 1;