Bug 32482: (follow-up) Add markup comments
[koha.git] / Koha / Old / Holds.pm
1 package Koha::Old::Holds;
2
3 # Copyright ByWater Solutions 2014
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Koha::Database;
23
24 use Koha::Old::Hold;
25
26 use base qw(Koha::Holds);
27
28 =head1 NAME
29
30 Koha::Old::Holds - Koha Old Hold object set class
31
32 This object represents a set of holds that have been filled or canceled
33
34 =head1 API
35
36 =head2 Class methods
37
38 =head3 filter_by_anonymizable
39
40     my $holds = $patron->old_holds;
41     my $anonymizable_holds = $holds->filter_by_anonymizable;
42
43 This method filters a I<Koha::Old::Holds> resultset, so it only contains holds that can be
44 anonymized given the patron privacy settings.
45
46 =cut
47
48 sub filter_by_anonymizable {
49     my ( $self, $params ) = @_;
50
51     my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef;
52
53     return $self->search(
54         {
55             'me.borrowernumber' => { 'not' => undef },
56             'patron.privacy' => { '<>'  => 0 },
57             (
58                 $anonymous_patron
59                 ? ( 'me.borrowernumber' => { '!=' => $anonymous_patron } )
60                 : ()
61             ),
62         },
63         {
64             join     => ['patron'],
65             order_by => ['me.reserve_id'],
66         }
67     );
68 }
69
70 =head3 anonymize
71
72     $patron->old_holds->anonymize();
73
74 Anonymize the given I<Koha::Old::Holds> resultset.
75
76 =cut
77
78 sub anonymize {
79     my ( $self, $params ) = @_;
80
81     my $anonymous_id = C4::Context->preference('AnonymousPatron');
82
83     Koha::Exceptions::SysPref::NotSet->throw( syspref => 'AnonymousPatron' )
84         unless $anonymous_id;
85
86     return $self->update( { borrowernumber => $anonymous_id }, { no_triggers => 1 } );
87 }
88
89 =head2 Internal methods
90
91 =head3 _type
92
93 =cut
94
95 sub _type {
96     return 'OldReserve';
97 }
98
99 =head3 object_class
100
101 =cut
102
103 sub object_class {
104     return 'Koha::Old::Hold';
105 }
106
107 =head1 AUTHOR
108
109 Kyle M Hall <kyle@bywatersolutions.com>
110
111 =cut
112
113 1;