Bug 35353: Add REST API endpoint to retrieve old holds
[koha.git] / Koha / Old / Hold.pm
1 package Koha::Old::Hold;
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 base qw(Koha::Hold);
23
24 use C4::Context;
25 use Koha::Exceptions::SysPref;
26
27 =head1 NAME
28
29 Koha::Old::Hold - Koha Old Hold object class
30
31 This object represents a hold that has been filled or canceled
32
33 =head1 API
34
35 =head2 Class methods
36
37 =head3 biblio
38
39 Returns the related Koha::Biblio object for this old hold
40
41 =cut
42
43 sub biblio {
44     my ($self) = @_;
45     my $rs = $self->_result->biblionumber;
46     return unless $rs;
47     return Koha::Biblio->_new_from_dbic($rs);
48 }
49
50 =head3 item
51
52 Returns the related Koha::Item object for this old Hold
53
54 =cut
55
56 sub item {
57     my ($self) = @_;
58     my $rs = $self->_result->itemnumber;
59     return unless $rs;
60     return Koha::Item->_new_from_dbic($rs);
61 }
62
63 =head3 pickup_library
64
65 Returns the related Koha::Biblio object for this old hold
66
67 =cut
68
69 sub pickup_library {
70     my ($self) = @_;
71     my $rs = $self->_result->pickup_library;
72     return unless $rs;
73     return Koha::Library->_new_from_dbic($rs);
74 }
75
76 =head3 anonymize
77
78     $old_hold->anonymize();
79
80 Anonymize the given I<Koha::Old::Hold> object.
81
82 =cut
83
84 sub anonymize {
85     my ($self) = @_;
86
87     my $anonymous_id = C4::Context->preference('AnonymousPatron');
88
89     Koha::Exceptions::SysPref::NotSet->throw( syspref => 'AnonymousPatron' )
90         unless $anonymous_id;
91
92     return $self->update( { borrowernumber => $anonymous_id } );
93 }
94
95 =head2 Internal methods
96
97 =head3 _type
98
99 =cut
100
101 sub _type {
102     return 'OldReserve';
103 }
104
105 =head1 AUTHOR
106
107 Kyle M Hall <kyle@bywatersolutions.com>
108
109 =cut
110
111 1;