Bug 14610 - Add and update modules
[koha.git] / Koha / Patrons.pm
1 package Koha::Patrons;
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
26 use Koha::ArticleRequests;
27 use Koha::ArticleRequest::Status;
28 use Koha::Patron;
29
30 use base qw(Koha::Objects);
31
32 =head1 NAME
33
34 Koha::Patron - Koha Patron Object class
35
36 =head1 API
37
38 =head2 Class Methods
39
40 =cut
41
42 =head3 search_housebound_choosers
43
44 Returns all Patrons which are Housebound choosers.
45
46 =cut
47
48 sub search_housebound_choosers {
49     my ( $self ) = @_;
50     my $cho = $self->_resultset
51         ->search_related('housebound_role', {
52             housebound_chooser => 1,
53         })->search_related('borrowernumber');
54     return Koha::Patrons->_new_from_dbic($cho);
55 }
56
57 =head3 search_housebound_deliverers
58
59 Returns all Patrons which are Housebound deliverers.
60
61 =cut
62
63 sub search_housebound_deliverers {
64     my ( $self ) = @_;
65     my $del = $self->_resultset
66         ->search_related('housebound_role', {
67             housebound_deliverer => 1,
68         })->search_related('borrowernumber');
69     return Koha::Patrons->_new_from_dbic($del);
70 }
71
72 =head3 guarantor
73
74 Returns a Koha::Patron object for this borrower's guarantor
75
76 =cut
77
78 sub guarantor {
79     my ( $self ) = @_;
80
81     return Koha::Patrons->find( $self->guarantorid() );
82 }
83
84 =head3 article_requests
85
86 my @requests = $borrower->article_requests();
87 my $requests = $borrower->article_requests();
88
89 Returns either a list of ArticleRequests objects,
90 or an ArtitleRequests object, depending on the
91 calling context.
92
93 =cut
94
95 sub article_requests {
96     my ( $self ) = @_;
97
98     $self->{_article_requests} ||= Koha::ArticleRequests->search({ borrowernumber => $self->borrowernumber() });
99
100     return $self->{_article_requests};
101 }
102
103 =head3 article_requests_current
104
105 my @requests = $patron->article_requests_current
106
107 Returns the article requests associated with this patron that are incomplete
108
109 =cut
110
111 sub article_requests_current {
112     my ( $self ) = @_;
113
114     $self->{_article_requests_current} ||= Koha::ArticleRequests->search(
115         {
116             borrowernumber => $self->id(),
117             -or          => [
118                 { status => Koha::ArticleRequest::Status::Pending },
119                 { status => Koha::ArticleRequest::Status::Processing }
120             ]
121         }
122     );
123
124     return $self->{_article_requests_current};
125 }
126
127 =head3 article_requests_finished
128
129 my @requests = $biblio->article_requests_finished
130
131 Returns the article requests associated with this patron that are completed
132
133 =cut
134
135 sub article_requests_finished {
136     my ( $self, $borrower ) = @_;
137
138     $self->{_article_requests_finished} ||= Koha::ArticleRequests->search(
139         {
140             borrowernumber => $self->id(),
141             -or          => [
142                 { status => Koha::ArticleRequest::Status::Completed },
143                 { status => Koha::ArticleRequest::Status::Canceled }
144             ]
145         }
146     );
147
148     return $self->{_article_requests_finished};
149 }
150
151 =head3 type
152
153 =cut
154
155 sub _type {
156     return 'Borrower';
157 }
158
159 sub object_class {
160     return 'Koha::Patron';
161 }
162
163 =head1 AUTHOR
164
165 Kyle M Hall <kyle@bywatersolutions.com>
166
167 =cut
168
169 1;