Bug 17600: Standardize our EXPORT_OK
[srvgit] / Koha / Patron / Relationships.pm
1 package Koha::Patron::Relationships;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use List::MoreUtils qw( uniq );
21
22 use Koha::Database;
23 use Koha::Patrons;
24 use Koha::Patron::Relationship;
25
26 use base qw(Koha::Objects);
27
28 =head1 NAME
29
30 Koha::Patron::Relationships - Koha Patron Relationship Object set class
31
32 =head1 API
33
34 =head2 Class Methods
35
36 =cut
37
38 =head3 guarantors
39
40 Returns all the guarantors in this set of relationships as a list of Koha::Patron objects
41 or as a Koha::Patrons object depending on the calling context
42
43 =cut
44
45 sub guarantors {
46     my ($self) = @_;
47
48     my $rs = $self->_resultset();
49
50     my @guarantor_ids = $rs->get_column('guarantor_id')->all();
51     # Guarantors may not have a guarantor_id, strip out undefs
52     @guarantor_ids = grep { defined $_ } @guarantor_ids;
53     @guarantor_ids = uniq( @guarantor_ids );
54
55     my $guarantors = Koha::Patrons->search( { borrowernumber => \@guarantor_ids } );
56
57     return wantarray ? $guarantors->as_list : $guarantors;
58 }
59
60 =head3 guarantees
61
62 Returns all the guarantees in this set of relationships as a list of Koha::Patron objects
63 or as a Koha::Patrons object depending on the calling context
64
65 =cut
66
67 sub guarantees {
68     my ($self) = @_;
69
70     my $rs = $self->_resultset();
71
72     my @guarantee_ids = uniq( $rs->get_column('guarantee_id')->all() );
73
74     my $guarantees = Koha::Patrons->search(
75         { borrowernumber => \@guarantee_ids },
76         {
77             order_by => { -asc => [ 'surname', 'firstname' ] }
78         },
79     );
80
81     return wantarray ? $guarantees->as_list : $guarantees;
82 }
83
84 =head3 type
85
86 =cut
87
88 sub _type {
89     return 'BorrowerRelationship';
90 }
91
92 =head3 object_class
93
94 =cut
95
96 sub object_class {
97     return 'Koha::Patron::Relationship';
98 }
99
100 1;