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 |
|
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 |
70 |
|
71 |
my @libraries = $group->libraries(); |
72 |
|
73 |
Returns the libraries set as direct children of this group |
74 |
|
75 |
=cut |
76 |
|
77 |
sub libraries { |
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 @libraries = map { $_->library() } @children; |
89 |
} |
90 |
|
91 |
=head3 libraries_not_direct_children |
92 |
|
93 |
my @libraries = $group->libraries_not_direct_children(); |
94 |
|
95 |
Returns the libraries set as direct children of this group |
96 |
|
97 |
=cut |
98 |
|
99 |
sub libraries_not_direct_children { |
100 |
my ($self) = @_; |
101 |
|
102 |
my @children = Koha::Library::Groups->search( |
103 |
{ |
104 |
parent_id => $self->id, |
105 |
branchcode => { '!=' => undef }, |
106 |
}, |
107 |
{ order_by => 'branchcode' } |
108 |
); |
109 |
|
110 |
my @branchcodes = map { $_->branchcode } @children; |
111 |
|
112 |
return Koha::Libraries->search( { branchcode => { -not_in => \@branchcodes } } ); |
113 |
} |
114 |
|
115 |
=head3 type |
116 |
|
117 |
=cut |
118 |
|
119 |
sub type { |
120 |
return 'LibraryGroup'; |
121 |
} |
122 |
|
123 |
=head1 AUTHOR |
124 |
|
125 |
Kyle M Hall <kyle@bywatersolutions.com> |
126 |
|
127 |
=cut |
128 |
|
129 |
1; |