Bug 26922: Regression tests
[koha.git] / Koha / Patron / HouseboundVisits.pm
blob49d6ae2d4a4d86abb0c3548eb85591a3dc117b28
1 package Koha::Patron::HouseboundVisits;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use Modern::Perl;
20 use Koha::Database;
21 use Koha::Patron::HouseboundVisit;
23 use base qw(Koha::Objects);
25 =head1 NAME
27 Koha::Patron::HouseboundVisits - Koha Patron HouseboundVisits Object class
29 =head1 SYNOPSIS
31 HouseboundVisits class used primarily by members/housebound.pl.
33 =head1 DESCRIPTION
35 Standard Koha::Objects definitions, and additional methods.
37 =head1 API
39 =head2 Class Methods
41 =cut
43 =head3 special_search;
45 my @houseboundVisits = Koha::HouseboundVisits->special_search($params, $attributes);
47 Perform a search for housebound visits. This method overrides standard search
48 to prefetch deliverers and choosers as we always need them anyway.
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.
53 This is intended to make search behave as most people would expect it to
54 behave.
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.
61 =cut
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'
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;
81 $self->SUPER::search($params, $attributes);
84 =head3 _type
86 =cut
88 sub _type {
89 return 'HouseboundVisit';
92 sub object_class {
93 return 'Koha::Patron::HouseboundVisit';
98 =head1 AUTHOR
100 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
102 =cut