Bug 16735: Use libraries in all subgroups, not just immediate children
[koha.git] / Koha / Library / Groups.pm
1 package Koha::Library::Groups;
2
3 # Copyright ByWater Solutions 2016
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use Carp;
23
24 use Koha::Database;
25
26 use Koha::Library::Group;
27
28 use base qw(Koha::Objects);
29
30 =head1 NAME
31
32 Koha::Library::Groups - Koha Library::Group object set class
33
34 =head1 API
35
36 =head2 Class Methods
37
38 =head3 my @root_groups = $self->get_root_group()
39
40 =cut
41
42 sub get_root_groups {
43     my ( $self ) = @_;
44
45     return $self->search( { parent_id => undef }, { order_by => 'title' } );
46 }
47
48 =head3 my @search_groups = $self->get_search_groups({[interface => 'staff' || 'opac']}))
49
50 Returns search groups for the specified interface.
51 Defaults to OPAC if no interface is specified.
52
53 =cut
54
55 sub get_search_groups {
56     my ( $self, $params ) = @_;
57     my $interface = $params->{interface} || q{};
58
59     my $title = $interface eq 'staff' ? '__SEARCH_GROUPS__' : '__SEARCH_GROUPS_OPAC__';
60
61     my ($search_groups_root) =
62       $self->search( { parent_id => undef, title => $title } );
63
64     return unless $search_groups_root;
65
66     my $children = $search_groups_root->children();
67
68     return wantarray ? $children->as_list : $children;
69 }
70
71 =head3 type
72
73 =cut
74
75 sub _type {
76     return 'LibraryGroup';
77 }
78
79 =head3 object_class
80
81 =cut
82
83 sub object_class {
84     return 'Koha::Library::Group';
85 }
86
87 =head1 AUTHOR
88
89 Kyle M Hall <kyle@bywatersolutions.com>
90
91 =cut
92
93 1;