3 # Copyright ByWater Solutions 2014
5 # This file is part of Koha.
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
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.
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.
27 use Koha
::ArticleRequests
;
28 use Koha
::ArticleRequest
::Status
;
31 use base
qw(Koha::Objects);
35 Koha::Patron - Koha Patron Object class
43 =head3 search_housebound_choosers
45 Returns all Patrons which are Housebound choosers.
49 sub search_housebound_choosers
{
51 my $cho = $self->_resultset
52 ->search_related('housebound_role', {
53 housebound_chooser
=> 1,
54 })->search_related('borrowernumber');
55 return Koha
::Patrons
->_new_from_dbic($cho);
58 =head3 search_housebound_deliverers
60 Returns all Patrons which are Housebound deliverers.
64 sub search_housebound_deliverers
{
66 my $del = $self->_resultset
67 ->search_related('housebound_role', {
68 housebound_deliverer
=> 1,
69 })->search_related('borrowernumber');
70 return Koha
::Patrons
->_new_from_dbic($del);
75 my $patrons = Koha::Patrons->search_upcoming_membership_expires();
77 The 'before' and 'after' represent the number of days before/after the date
78 that is set by the preference MembershipExpiryDaysNotice.
79 If the pref is 14, before 2 and after 3 then you will get all expires
84 sub search_upcoming_membership_expires
{
85 my ( $self, $params ) = @_;
86 my $before = $params->{before
} || 0;
87 my $after = $params->{after
} || 0;
88 delete $params->{before
};
89 delete $params->{after
};
91 my $days = C4
::Context
->preference("MembershipExpiryDaysNotice") || 0;
92 my $date_before = dt_from_string
->add( days
=> $days - $before );
93 my $date_after = dt_from_string
->add( days
=> $days + $after );
94 my $dtf = Koha
::Database
->new->schema->storage->datetime_parser;
96 $params->{dateexpiry
} = {
97 ">=" => $dtf->format_date( $date_before ),
98 "<=" => $dtf->format_date( $date_after ),
100 return $self->SUPER::search
(
101 $params, { join => ['branchcode', 'categorycode'] }
107 Returns a Koha::Patron object for this borrower's guarantor
114 return Koha
::Patrons
->find( $self->guarantorid() );
117 =head3 article_requests
119 my @requests = $borrower->article_requests();
120 my $requests = $borrower->article_requests();
122 Returns either a list of ArticleRequests objects,
123 or an ArtitleRequests object, depending on the
128 sub article_requests
{
131 $self->{_article_requests
} ||= Koha
::ArticleRequests
->search({ borrowernumber
=> $self->borrowernumber() });
133 return $self->{_article_requests
};
136 =head3 article_requests_current
138 my @requests = $patron->article_requests_current
140 Returns the article requests associated with this patron that are incomplete
144 sub article_requests_current
{
147 $self->{_article_requests_current
} ||= Koha
::ArticleRequests
->search(
149 borrowernumber
=> $self->id(),
151 { status
=> Koha
::ArticleRequest
::Status
::Pending
},
152 { status
=> Koha
::ArticleRequest
::Status
::Processing
}
157 return $self->{_article_requests_current
};
160 =head3 article_requests_finished
162 my @requests = $biblio->article_requests_finished
164 Returns the article requests associated with this patron that are completed
168 sub article_requests_finished
{
169 my ( $self, $borrower ) = @_;
171 $self->{_article_requests_finished
} ||= Koha
::ArticleRequests
->search(
173 borrowernumber
=> $self->id(),
175 { status
=> Koha
::ArticleRequest
::Status
::Completed
},
176 { status
=> Koha
::ArticleRequest
::Status
::Canceled
}
181 return $self->{_article_requests_finished
};
193 return 'Koha::Patron';
198 Kyle M Hall <kyle@bywatersolutions.com>