|
Line 0
Link Here
|
|
|
1 |
package Koha::Library::Group; |
| 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 |
use Koha::DateUtils qw(dt_from_string); |
| 26 |
use Koha::Libraries; |
| 27 |
|
| 28 |
use base qw(Koha::Object); |
| 29 |
|
| 30 |
=head1 NAME |
| 31 |
|
| 32 |
Koha::Library::Group - Koha Library::Group object class |
| 33 |
|
| 34 |
=head1 API |
| 35 |
|
| 36 |
=head2 Class Methods |
| 37 |
|
| 38 |
=cut |
| 39 |
|
| 40 |
=head3 my @children = $self->get_children() |
| 41 |
|
| 42 |
=cut |
| 43 |
|
| 44 |
sub children { |
| 45 |
my ($self) = @_; |
| 46 |
|
| 47 |
my $children = |
| 48 |
Koha::Library::Groups->search( { parent_id => $self->id }, { order_by => [ 'title', 'branchcode' ] } ); |
| 49 |
|
| 50 |
return $children; |
| 51 |
} |
| 52 |
|
| 53 |
=head3 library |
| 54 |
|
| 55 |
my $library = $group->library(); |
| 56 |
|
| 57 |
Returns the library for this group if one exists |
| 58 |
|
| 59 |
=cut |
| 60 |
|
| 61 |
sub library { |
| 62 |
my ($self) = @_; |
| 63 |
|
| 64 |
return unless $self->branchcode; |
| 65 |
|
| 66 |
return Koha::Libraries->find( $self->branchcode ); |
| 67 |
} |
| 68 |
|
| 69 |
=head3 libraries_not_direct_children |
| 70 |
|
| 71 |
my @libraries = $group->libraries_not_direct_children(); |
| 72 |
|
| 73 |
Returns the libraries *not* set as direct children of this group |
| 74 |
|
| 75 |
=cut |
| 76 |
|
| 77 |
sub libraries_not_direct_children { |
| 78 |
my ($self) = @_; |
| 79 |
|
| 80 |
my @children = Koha::Library::Groups->search( |
| 81 |
{ |
| 82 |
parent_id => $self->id, |
| 83 |
branchcode => { '!=' => undef }, |
| 84 |
}, |
| 85 |
{ order_by => 'branchcode' } |
| 86 |
); |
| 87 |
|
| 88 |
my @branchcodes = map { $_->branchcode } @children; |
| 89 |
|
| 90 |
return Koha::Libraries->search( { branchcode => { -not_in => \@branchcodes } } ); |
| 91 |
} |
| 92 |
|
| 93 |
=head3 store |
| 94 |
|
| 95 |
=cut |
| 96 |
|
| 97 |
sub store { |
| 98 |
my ($self) = @_; |
| 99 |
|
| 100 |
my $now = dt_from_string; |
| 101 |
$self->updated_on($now); |
| 102 |
$self->created_on($now) unless $self->in_storage(); |
| 103 |
|
| 104 |
return $self->SUPER::store(@_); |
| 105 |
} |
| 106 |
|
| 107 |
=head3 type |
| 108 |
|
| 109 |
=cut |
| 110 |
|
| 111 |
sub type { |
| 112 |
return 'LibraryGroup'; |
| 113 |
} |
| 114 |
|
| 115 |
=head1 AUTHOR |
| 116 |
|
| 117 |
Kyle M Hall <kyle@bywatersolutions.com> |
| 118 |
|
| 119 |
=cut |
| 120 |
|
| 121 |
1; |