Bug 26922: Regression tests
[koha.git] / Koha / Patron / Relationships.pm
blob7c2a9bc51f436c0061400ce74cd2c798d2f870dc
1 package Koha::Patron::Relationships;
3 # This file is part of Koha.
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.
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.
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>.
18 use Modern::Perl;
20 use Carp;
21 use List::MoreUtils qw( uniq );
23 use Koha::Database;
24 use Koha::Patrons;
25 use Koha::Patron::Relationship;
27 use base qw(Koha::Objects);
29 =head1 NAME
31 Koha::Patron::Relationships - Koha Patron Relationship Object set class
33 =head1 API
35 =head2 Class Methods
37 =cut
39 =head3 guarantors
41 Returns all the guarantors in this set of relationships as a list of Koha::Patron objects
42 or as a Koha::Patrons object depending on the calling context
44 =cut
46 sub guarantors {
47 my ($self) = @_;
49 my $rs = $self->_resultset();
51 my @guarantor_ids = $rs->get_column('guarantor_id')->all();
52 # Guarantors may not have a guarantor_id, strip out undefs
53 @guarantor_ids = grep { defined $_ } @guarantor_ids;
54 @guarantor_ids = uniq( @guarantor_ids );
56 my $guarantors = Koha::Patrons->search( { borrowernumber => \@guarantor_ids } );
58 return wantarray ? $guarantors->as_list : $guarantors;
61 =head3 guarantees
63 Returns all the guarantees in this set of relationships as a list of Koha::Patron objects
64 or as a Koha::Patrons object depending on the calling context
66 =cut
68 sub guarantees {
69 my ($self) = @_;
71 my $rs = $self->_resultset();
73 my @guarantee_ids = uniq( $rs->get_column('guarantee_id')->all() );
75 my $guarantees = Koha::Patrons->search(
76 { borrowernumber => \@guarantee_ids },
78 order_by => { -asc => [ 'surname', 'firstname' ] }
82 return wantarray ? $guarantees->as_list : $guarantees;
85 =head3 type
87 =cut
89 sub _type {
90 return 'BorrowerRelationship';
93 =head3 object_class
95 =cut
97 sub object_class {
98 return 'Koha::Patron::Relationship';