Bug 23791: DBRev 19.06.00.041
[koha.git] / Koha / Patron / HouseboundVisits.pm
1 package Koha::Patron::HouseboundVisits;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 use Modern::Perl;
19
20 use Koha::Database;
21 use Koha::Patron::HouseboundVisit;
22
23 use base qw(Koha::Objects);
24
25 =head1 NAME
26
27 Koha::Patron::HouseboundVisits - Koha Patron HouseboundVisits Object class
28
29 =head1 SYNOPSIS
30
31 HouseboundVisits class used primarily by members/housebound.pl.
32
33 =head1 DESCRIPTION
34
35 Standard Koha::Objects definitions, and additional methods.
36
37 =head1 API
38
39 =head2 Class Methods
40
41 =cut
42
43 =head3 special_search;
44
45    my @houseboundVisits = Koha::HouseboundVisits->special_search($params, $attributes);
46
47 Perform a search for housebound visits.  This method overrides standard search
48 to prefetch deliverers and choosers as we always need them anyway.
49
50 If $attributes contains a prefetch entry, we defer to it, otherwise we add the
51 prefetch attribute and also augment $params with explicit 'me.' prefixes.
52
53 This is intended to make search behave as most people would expect it to
54 behave.
55
56 Should the user want to do complicated searches involving joins, without
57 specifying their own prefetch, the naive 'me.' augmentation will break in
58 hilarious ways.  In this case the user should supply their own prefetch
59 clause.
60
61 =cut
62
63 sub special_search {
64     my ( $self, $params, $attributes ) = @_;
65     unless (exists $attributes->{prefetch}) {
66         # No explicit prefetch has been passed in -> automatic optimisation.
67         $attributes->{prefetch} = [
68             'chooser_brwnumber', 'deliverer_brwnumber'
69         ];
70         # So we must ensure our $params use the 'me.' prefix.
71         my $oldparams = $params;
72         $params = {};
73         while (my ($k, $v) = each %{$oldparams}) {
74             if ($k =~ /^me\..*/) {
75                 $params->{$k} = $v;
76             } else {
77                 $params->{"me." . $k} = $v;
78             }
79         }
80     }
81     $self->SUPER::search($params, $attributes);
82 }
83
84 =head3 _type
85
86 =cut
87
88 sub _type {
89     return 'HouseboundVisit';
90 }
91
92 sub object_class {
93     return 'Koha::Patron::HouseboundVisit';
94 }
95
96 1;
97
98 =head1 AUTHOR
99
100 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
101
102 =cut