Bug 17600: Standardize our EXPORT_OK
[srvgit] / 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
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
25 use Koha::Library::Group;
26
27 use base qw(Koha::Objects);
28
29 =head1 NAME
30
31 Koha::Library::Groups - Koha Library::Group object set class
32
33 =head1 API
34
35 =head2 Class Methods
36
37 =head3 get_root_groups
38
39 my @root_groups = $self->get_root_group()
40
41 =cut
42
43 sub get_root_groups {
44     my ( $self ) = @_;
45
46     return $self->search( { parent_id => undef }, { order_by => 'title' } );
47 }
48
49 =head3 get_search_groups
50
51 my @search_groups = $self->get_search_groups({[interface => 'staff' || 'opac']}))
52
53 Returns search groups for the specified interface.
54 Defaults to OPAC if no interface is specified.
55
56 =cut
57
58 sub get_search_groups {
59     my ( $self, $params ) = @_;
60     my $interface = $params->{interface} || q{};
61
62     my $field = $interface eq 'staff' ? 'ft_search_groups_staff' : 'ft_search_groups_opac';
63
64     return $self->search( { $field => 1 } );
65 }
66
67
68 =head3 get_root_ancestor
69
70 my $root_ancestor = $self->get_root_ancestor( {id => $group_id } )
71
72 Retrieve root ancestor group for a specified id.
73
74 =cut
75
76 sub get_root_ancestor {
77     my ( $self, $params ) = @_;
78     my $row = $self->find($params);
79     return $row unless $row->parent_id;
80     return $self->get_root_ancestor( { id => $row->parent_id } );
81 }
82
83
84 =head3 type
85
86 =cut
87
88 sub _type {
89     return 'LibraryGroup';
90 }
91
92 =head3 object_class
93
94 =cut
95
96 sub object_class {
97     return 'Koha::Library::Group';
98 }
99
100 =head1 AUTHOR
101
102 Kyle M Hall <kyle@bywatersolutions.com>
103
104 =cut
105
106 1;