Bug 27344: Fix tests
[koha.git] / Koha / Suggestions.pm
1 package Koha::Suggestions;
2
3 # Copyright ByWater Solutions 2015
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
23 use Koha::Database;
24 use Koha::Suggestion;
25
26 use base qw(Koha::Objects);
27
28 =head1 NAME
29
30 Koha::Suggestions - Koha Suggestion object set class
31
32 =head1 API
33
34 =head2 Class methods
35
36 =head3 search_limited
37
38     my $suggestions = Koha::Suggestions->search_limited( $params, $attributes );
39
40 Returns all the suggestions the logged in user is allowed to see.
41
42 =cut
43
44 sub search_limited {
45     my ( $self, $params, $attributes ) = @_;
46
47     my $resultset = $self;
48
49     # filter on user branch
50     if (   C4::Context->preference('IndependentBranches')
51         && !C4::Context->IsSuperLibrarian() )
52     {
53         # If IndependentBranches is set and the logged in user is not superlibrarian
54         # Then we want to filter by the user's library (i.e. cannot see suggestions
55         # from other libraries)
56         my $userenv = C4::Context->userenv;
57
58         $resultset = $self->search({ branchcode => $userenv->{branch} })
59             if $userenv && $userenv->{branch};
60     }
61
62     return $resultset->search( $params, $attributes);
63 }
64
65 =head2 Internal methods
66
67 =head3 _type
68
69 =cut
70
71 sub _type {
72     return 'Suggestion';
73 }
74
75 =head3 object_class
76
77 =cut
78
79 sub object_class {
80     return 'Koha::Suggestion';
81 }
82
83 =head1 AUTHOR
84
85 Kyle M Hall <kyle@bywatersolutions.com>
86
87 =cut
88
89 1;