Bug 15656: Move guarantor/guarantees code - GetMemberRelatives
[koha.git] / Koha / Patron.pm
1 package Koha::Patron;
2
3 # Copyright ByWater Solutions 2014
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::Patron::Images;
26
27 use base qw(Koha::Object);
28
29 =head1 NAME
30
31 Koha::Patron - Koha Patron Object class
32
33 =head1 API
34
35 =head2 Class Methods
36
37 =cut
38
39 =head3 guarantor
40
41 Returns a Koha::Patron object for this patron's guarantor
42
43 =cut
44
45 sub guarantor {
46     my ( $self ) = @_;
47
48     return Koha::Patrons->find( $self->guarantorid() );
49 }
50
51 sub image {
52     my ( $self ) = @_;
53
54     return Koha::Patron::Images->find( $self->borrowernumber )
55 }
56
57 =head3 guarantees
58
59 Returns the guarantees (list of Koha::Patron) of this patron
60
61 =cut
62
63 sub guarantees {
64     my ( $self ) = @_;
65
66     return Koha::Patrons->search({ guarantorid => $self->borrowernumber });
67 }
68
69 =head3 siblings
70
71 Returns the siblings of this patron.
72
73 =cut
74
75 sub siblings {
76     my ( $self ) = @_;
77
78     my $guarantor = $self->guarantor;
79     my $guarantorid = $guarantor ? $guarantor->borrowernumber : undef;
80
81     return Koha::Patrons->search(
82         {
83             guarantorid => {
84                 '!=' => undef,
85                 '=' => $guarantorid,
86             },
87             borrowernumber => {
88                 '!=' => $self->borrowernumber,
89             }
90         }
91     );
92 }
93
94 =head3 type
95
96 =cut
97
98 sub _type {
99     return 'Borrower';
100 }
101
102 =head1 AUTHOR
103
104 Kyle M Hall <kyle@bywatersolutions.com>
105
106 =cut
107
108 1;