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' ] } );
62 return wantarray ?
$children->as_list : $children;
67 my $has_child = $group->has_child( $branchcode );
69 Return true if the given branchcode library is a child of this group.
74 my ( $self, $branchcode ) = @_;
75 return unless $branchcode; # Does not support group of libraries.
76 return ( grep { $_ and $_ eq $branchcode }
77 $self->children->get_column('branchcode') ) ?
1 : 0;
82 my $library = $group->library();
84 Returns the library for this group if one exists
91 return unless $self->branchcode;
93 $self->{_library
} ||= Koha
::Libraries
->find( $self->branchcode );
95 return $self->{_library
};
100 my @libraries = $group->libraries( { [invert => 1] } );
102 Returns the libraries set as direct children of this group.
104 If invert param is true, the returned list will be libraries
105 that are *not* direct children of this group.
110 my ($self, $params) = @_;
111 my $invert = $params->{invert
};
113 my $in_or_not = $invert ?
'-not_in' : '-in';
115 my @children = Koha
::Library
::Groups
->search(
117 parent_id
=> $self->id,
118 branchcode
=> { '!=' => undef },
120 { order_by
=> 'branchcode' }
123 my @branchcodes = map { $_->branchcode } @children;
125 return Koha
::Libraries
->search(
127 branchcode
=> { $in_or_not => \
@branchcodes }
130 order_by
=> 'branchname'
137 my @libraries = $group->all_libraries( { [invert => 1] } );
139 Returns the libraries set as children of this group or any subgroup.
144 my ( $self, $params ) = @_;
148 my @children = $self->children;
149 foreach my $c (@children) {
150 if ( $c->branchcode ) {
151 push( @libraries, $c->library );
154 push( @libraries, $c->all_libraries );
160 grep { !$seen{ $_->id }++ } @libraries;
165 =head3 libraries_not_direct_children
167 my @libraries = $group->libraries_not_direct_children();
169 Returns the libraries *not* set as direct children of this group
173 sub libraries_not_direct_children
{
176 return $self->libraries( { invert
=> 1 } );
186 $self->created_on( dt_from_string
() ) unless $self->in_storage();
188 return $self->SUPER::store
(@_);
191 =head2 Internal methods
198 return 'LibraryGroup';
203 Kyle M Hall <kyle@bywatersolutions.com>