Bug 9468: use new SUGGEST_FORMAT list
[koha.git] / Koha / Hold.pm
1 package Koha::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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use Carp;
23
24 use C4::Context qw(preference);
25 use Koha::Branches;
26 use Koha::Biblios;
27 use Koha::Items;
28 use Koha::DateUtils qw(dt_from_string);
29
30 use base qw(Koha::Object);
31
32 =head1 NAME
33
34 Koha::Hold - Koha Hold object class
35
36 =head1 API
37
38 =head2 Class Methods
39
40 =cut
41
42 =head3 waiting_expires_on
43
44 Returns a DateTime for the date a waiting holds expires on.
45 Returns undef if the system peference ReservesMaxPickUpDelay is not set.
46 Returns undef if the hold is not waiting ( found = 'W' ).
47
48 =cut
49
50 sub waiting_expires_on {
51     my ($self) = @_;
52
53     my $found = $self->found;
54     return unless $found && $found eq 'W';
55
56     my $ReservesMaxPickUpDelay = C4::Context->preference('ReservesMaxPickUpDelay');
57     return unless $ReservesMaxPickUpDelay;
58
59     my $dt = dt_from_string( $self->waitingdate() );
60
61     $dt->add( days => $ReservesMaxPickUpDelay );
62
63     return $dt;
64 }
65
66 =head3 is_waiting
67
68 Returns true if hold is a waiting hold
69
70 =cut
71
72 sub is_waiting {
73     my ($self) = @_;
74
75     my $found = $self->found;
76     return $found && $found eq 'W';
77 }
78
79 =head3 biblio
80
81 Returns the related Koha::Biblio object for this hold
82
83 =cut
84
85 sub biblio {
86     my ($self) = @_;
87
88     $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
89
90     return $self->{_biblio};
91 }
92
93 =head3 item
94
95 Returns the related Koha::Item object for this Hold
96
97 =cut
98
99 sub item {
100     my ($self) = @_;
101
102     $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
103
104     return $self->{_item};
105 }
106
107 =head3 branch
108
109 Returns the related Koha::Branch object for this Hold
110
111 =cut
112
113 sub branch {
114     my ($self) = @_;
115
116     $self->{_branch} ||= Koha::Branches->find( $self->branchcode() );
117
118     return $self->{_branch};
119 }
120
121 =head3 type
122
123 =cut
124
125 sub type {
126     return 'Reserve';
127 }
128
129 =head1 AUTHOR
130
131 Kyle M Hall <kyle@bywatersolutions.com>
132
133 =cut
134
135 1;