1 package Koha::Library::Group;
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 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
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.
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.
25 use Koha::DateUtils qw(dt_from_string);
28 use base qw(Koha::Object);
32 Koha::Library::Group - Koha Library::Group object class
40 =head3 my @parent = $self->parent()
47 $self->{_parent} ||= Koha::Library::Groups->find( $self->parent_id );
49 return $self->{_parent};
52 =head3 my @children = $self->children()
60 Koha::Library::Groups->search( { parent_id => $self->id }, { order_by => [ 'title', 'branchcode' ] } );
67 my $library = $group->library();
69 Returns the library for this group if one exists
76 return unless $self->branchcode;
78 $self->{_library} ||= Koha::Libraries->find( $self->branchcode );
80 return $self->{_library};
83 =head3 libraries_not_direct_children
85 my @libraries = $group->libraries_not_direct_children();
87 Returns the libraries *not* set as direct children of this group
91 sub libraries_not_direct_children {
94 my @children = Koha::Library::Groups->search(
96 parent_id => $self->id,
97 branchcode => { '!=' => undef },
99 { order_by => 'branchcode' }
102 my @branchcodes = map { $_->branchcode } @children;
104 return Koha::Libraries->search(
106 branchcode => { -not_in => \@branchcodes }
109 order_by => 'branchname'
121 $self->created_on( dt_from_string() ) unless $self->in_storage();
123 return $self->SUPER::store(@_);
131 return 'LibraryGroup';
136 Kyle M Hall <kyle@bywatersolutions.com>