Bug 15006: [QA Follow-up] Satisfy qa tools with one tab less
[koha.git] / Koha / Patron.pm
blob5ba5efca98e19956bb6bbb3244e0a1a3f9bfe1a4
1 package Koha::Patron;
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
11 # version.
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.
21 use Modern::Perl;
23 use Carp;
25 use C4::Context;
26 use Koha::Database;
27 use Koha::Issues;
28 use Koha::OldIssues;
29 use Koha::Patron::Categories;
30 use Koha::Patron::Images;
31 use Koha::Patrons;
33 use base qw(Koha::Object);
35 =head1 NAME
37 Koha::Patron - Koha Patron Object class
39 =head1 API
41 =head2 Class Methods
43 =cut
45 =head3 guarantor
47 Returns a Koha::Patron object for this patron's guarantor
49 =cut
51 sub guarantor {
52 my ( $self ) = @_;
54 return unless $self->guarantorid();
56 return Koha::Patrons->find( $self->guarantorid() );
59 sub image {
60 my ( $self ) = @_;
62 return Koha::Patron::Images->find( $self->borrowernumber )
65 =head3 guarantees
67 Returns the guarantees (list of Koha::Patron) of this patron
69 =cut
71 sub guarantees {
72 my ( $self ) = @_;
74 return Koha::Patrons->search( { guarantorid => $self->borrowernumber } );
77 =head3 siblings
79 Returns the siblings of this patron.
81 =cut
83 sub siblings {
84 my ( $self ) = @_;
86 my $guarantor = $self->guarantor;
88 return unless $guarantor;
90 return Koha::Patrons->search(
92 guarantorid => {
93 '!=' => undef,
94 '=' => $guarantor->id,
96 borrowernumber => {
97 '!=' => $self->borrowernumber,
103 =head3 wants_check_for_previous_checkout
105 $wants_check = $patron->wants_check_for_previous_checkout;
107 Return 1 if Koha needs to perform PrevIssue checking, else 0.
109 =cut
111 sub wants_check_for_previous_checkout {
112 my ( $self ) = @_;
113 my $syspref = C4::Context->preference("checkPrevCheckout");
115 # Simple cases
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') {
131 return 1;
132 } else {
133 return 0;
137 =head3 do_check_for_previous_checkout
139 $do_check = $patron->do_check_for_previous_checkout($item);
141 Return 1 if the bib associated with $ITEM has previously been checked out to
142 $PATRON, 0 otherwise.
144 =cut
146 sub do_check_for_previous_checkout {
147 my ( $self, $item ) = @_;
149 # Find all items for bib and extract item numbers.
150 my @items = Koha::Items->search({biblionumber => $item->{biblionumber}});
151 my @item_nos;
152 foreach my $item (@items) {
153 push @item_nos, $item->itemnumber;
156 # Create (old)issues search criteria
157 my $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
171 =head3 type
173 =cut
175 sub _type {
176 return 'Borrower';
179 =head1 AUTHOR
181 Kyle M Hall <kyle@bywatersolutions.com>
182 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
184 =cut