Bug 26922: Regression tests
[koha.git] / Koha / Library / Groups.pm
blobdc17c21c51981f0a99b96f63126ae2a7531ff72a
1 package Koha::Library::Groups;
3 # Copyright ByWater Solutions 2016
5 # This file is part of Koha.
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.
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.
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>.
20 use Modern::Perl;
22 use Carp;
24 use Koha::Database;
26 use Koha::Library::Group;
28 use base qw(Koha::Objects);
30 =head1 NAME
32 Koha::Library::Groups - Koha Library::Group object set class
34 =head1 API
36 =head2 Class Methods
38 =head3 get_root_groups
40 my @root_groups = $self->get_root_group()
42 =cut
44 sub get_root_groups {
45 my ( $self ) = @_;
47 return $self->search( { parent_id => undef }, { order_by => 'title' } );
50 =head3 get_search_groups
52 my @search_groups = $self->get_search_groups({[interface => 'staff' || 'opac']}))
54 Returns search groups for the specified interface.
55 Defaults to OPAC if no interface is specified.
57 =cut
59 sub get_search_groups {
60 my ( $self, $params ) = @_;
61 my $interface = $params->{interface} || q{};
63 my $field = $interface eq 'staff' ? 'ft_search_groups_staff' : 'ft_search_groups_opac';
65 return $self->search( { $field => 1 } );
69 =head3 get_root_ancestor
71 my $root_ancestor = $self->get_root_ancestor( {id => $group_id } )
73 Retrieve root ancestor group for a specified id.
75 =cut
77 sub get_root_ancestor {
78 my ( $self, $params ) = @_;
79 my $row = $self->find($params);
80 return $row unless $row->parent_id;
81 return $self->get_root_ancestor( { id => $row->parent_id } );
85 =head3 type
87 =cut
89 sub _type {
90 return 'LibraryGroup';
93 =head3 object_class
95 =cut
97 sub object_class {
98 return 'Koha::Library::Group';
101 =head1 AUTHOR
103 Kyle M Hall <kyle@bywatersolutions.com>
105 =cut