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.
29 use Koha::Patron::Categories;
30 use Koha::Patron::Images;
33 use base qw(Koha::Object);
37 Koha::Patron - Koha Patron Object class
47 Returns a Koha::Patron object for this patron's guarantor
54 return unless $self->guarantorid();
56 return Koha::Patrons->find( $self->guarantorid() );
62 return Koha::Patron::Images->find( $self->borrowernumber )
67 Returns the guarantees (list of Koha::Patron) of this patron
74 return Koha::Patrons->search( { guarantorid => $self->borrowernumber } );
79 Returns the siblings of this patron.
86 my $guarantor = $self->guarantor;
88 return unless $guarantor;
90 return Koha::Patrons->search(
94 '=' => $guarantor->id,
97 '!=' => $self->borrowernumber,
103 =head3 wantsCheckPrevCheckout
105 $wantsCheckPrevCheckout = $patron->wantsCheckPrevCheckout;
107 Return 1 if Koha needs to perform PrevIssue checking, else 0.
111 sub wantsCheckPrevCheckout {
113 my $syspref = C4::Context->preference("checkPrevCheckout");
116 ## Hard syspref trumps all
117 return 1 if ($syspref eq 'hardyes');
118 return 0 if ($syspref eq 'hardno');
119 ## Now, patron pref trumps all
120 return 1 if ($self->checkprevcheckout eq 'yes');
121 return 0 if ($self->checkprevcheckout eq 'no');
123 # More complex: patron inherits -> determine category preference
124 my $checkPrevCheckoutByCat = Koha::Patron::Categories
125 ->find($self->categorycode)->checkprevcheckout;
126 return 1 if ($checkPrevCheckoutByCat eq 'yes');
127 return 0 if ($checkPrevCheckoutByCat eq 'no');
129 # Finally: category preference is inherit, default to 0
130 if ($syspref eq 'softyes') {
137 =head3 doCheckPrevCheckout
139 $checkPrevCheckout = $patron->doCheckPrevCheckout($item);
141 Return 1 if the bib associated with $ITEM has previously been checked out to
142 $PATRON, 0 otherwise.
146 sub doCheckPrevCheckout {
147 my ( $self, $item ) = @_;
149 # Find all items for bib and extract item numbers.
150 my @items = Koha::Items->search({biblionumber => $item->{biblionumber}});
152 foreach my $item (@items) {
153 push @item_nos, $item->itemnumber;
156 # Create (old)issues search criteria
158 borrowernumber => $self->borrowernumber,
159 itemnumber => \@item_nos,
162 # Check current issues table
163 my $issues = Koha::Issues->search($criteria);
164 return 1 if $issues->count; # 0 || N
166 # Check old issues table
167 my $old_issues = Koha::OldIssues->search($criteria);
168 return $old_issues->count; # 0 || N
181 Kyle M Hall <kyle@bywatersolutions.com>
182 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>