3 # Copyright ByWater Solutions 2014
4 # Copyright PTFS Europe 2016
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 3 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 use Koha::Patron::Categories;
31 use Koha::Patron::Images;
34 use base qw(Koha::Object);
38 Koha::Patron - Koha Patron Object class
48 Returns a Koha::Patron object for this patron's guarantor
55 return unless $self->guarantorid();
57 return Koha::Patrons->find( $self->guarantorid() );
63 return Koha::Patron::Images->find( $self->borrowernumber )
68 Returns the guarantees (list of Koha::Patron) of this patron
75 return Koha::Patrons->search( { guarantorid => $self->borrowernumber } );
80 Returns the siblings of this patron.
87 my $guarantor = $self->guarantor;
89 return unless $guarantor;
91 return Koha::Patrons->search(
95 '=' => $guarantor->id,
98 '!=' => $self->borrowernumber,
104 =head3 wants_check_for_previous_checkout
106 $wants_check = $patron->wants_check_for_previous_checkout;
108 Return 1 if Koha needs to perform PrevIssue checking, else 0.
112 sub wants_check_for_previous_checkout {
114 my $syspref = C4::Context->preference("checkPrevCheckout");
117 ## Hard syspref trumps all
118 return 1 if ($syspref eq 'hardyes');
119 return 0 if ($syspref eq 'hardno');
120 ## Now, patron pref trumps all
121 return 1 if ($self->checkprevcheckout eq 'yes');
122 return 0 if ($self->checkprevcheckout eq 'no');
124 # More complex: patron inherits -> determine category preference
125 my $checkPrevCheckoutByCat = Koha::Patron::Categories
126 ->find($self->categorycode)->checkprevcheckout;
127 return 1 if ($checkPrevCheckoutByCat eq 'yes');
128 return 0 if ($checkPrevCheckoutByCat eq 'no');
130 # Finally: category preference is inherit, default to 0
131 if ($syspref eq 'softyes') {
138 =head3 do_check_for_previous_checkout
140 $do_check = $patron->do_check_for_previous_checkout($item);
142 Return 1 if the bib associated with $ITEM has previously been checked out to
143 $PATRON, 0 otherwise.
147 sub do_check_for_previous_checkout {
148 my ( $self, $item ) = @_;
150 # Find all items for bib and extract item numbers.
151 my @items = Koha::Items->search({biblionumber => $item->{biblionumber}});
153 foreach my $item (@items) {
154 push @item_nos, $item->itemnumber;
157 # Create (old)issues search criteria
159 borrowernumber => $self->borrowernumber,
160 itemnumber => \@item_nos,
163 # Check current issues table
164 my $issues = Koha::Issues->search($criteria);
165 return 1 if $issues->count; # 0 || N
167 # Check old issues table
168 my $old_issues = Koha::OldIssues->search($criteria);
169 return $old_issues->count; # 0 || N
174 my $debarment_expiration = $patron->is_debarred;
176 Returns the date a patron debarment will expire, or undef if the patron is not
184 return unless $self->debarred;
185 return $self->debarred
186 if $self->debarred =~ '^9999'
187 or dt_from_string( $self->debarred ) > dt_from_string;
201 Kyle M Hall <kyle@bywatersolutions.com>
202 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>