Bug 17600: Standardize our EXPORT_OK
[srvgit] / Koha / ArticleRequest.pm
1 package Koha::ArticleRequest;
2
3 # Copyright ByWater Solutions 2015
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
23 use Koha::Database;
24 use Koha::Patrons;
25 use Koha::Biblios;
26 use Koha::Items;
27 use Koha::Libraries;
28 use Koha::DateUtils qw( dt_from_string );
29
30 use base qw(Koha::Object);
31
32 =head1 NAME
33
34 Koha::ArticleRequest - Koha Article Request Object class
35
36 =head1 API
37
38 =head2 Class Methods
39
40 =cut
41
42 =head3 open
43
44 =cut
45
46 sub open {
47     my ($self) = @_;
48
49     $self->status(Koha::ArticleRequest::Status::Pending);
50     $self->SUPER::store();
51     $self->notify();
52     return $self;
53 }
54
55 =head3 process
56
57 =cut
58
59 sub process {
60     my ($self) = @_;
61
62     $self->status(Koha::ArticleRequest::Status::Processing);
63     $self->store();
64     $self->notify();
65     return $self;
66 }
67
68 =head3 complete
69
70 =cut
71
72 sub complete {
73     my ($self) = @_;
74
75     $self->status(Koha::ArticleRequest::Status::Completed);
76     $self->store();
77     $self->notify();
78     return $self;
79 }
80
81 =head3 cancel
82
83 =cut
84
85 sub cancel {
86     my ( $self, $notes ) = @_;
87
88     $self->status(Koha::ArticleRequest::Status::Canceled);
89     $self->notes($notes) if $notes;
90     $self->store();
91     $self->notify();
92     return $self;
93 }
94
95 =head3 notify
96
97 =cut
98
99 sub notify {
100     my ($self) = @_;
101
102     my $status = $self->status;
103
104     require C4::Letters;
105     if (
106         my $letter = C4::Letters::GetPreparedLetter(
107             module                 => 'circulation',
108             letter_code            => "AR_$status", # AR_PENDING, AR_PROCESSING, AR_COMPLETED, AR_CANCELED
109             message_transport_type => 'email',
110             lang                   => $self->borrower->lang,
111             tables                 => {
112                 article_requests => $self->id,
113                 borrowers        => $self->borrowernumber,
114                 biblio           => $self->biblionumber,
115                 biblioitems      => $self->biblionumber,
116                 items            => $self->itemnumber,
117                 branches         => $self->branchcode,
118             },
119         )
120       )
121     {
122         C4::Letters::EnqueueLetter(
123             {
124                 letter                 => $letter,
125                 borrowernumber         => $self->borrowernumber,
126                 message_transport_type => 'email',
127             }
128         ) or warn "can't enqueue letter ". $letter->{code};
129     }
130 }
131
132 =head3 biblio
133
134 Returns the Koha::Biblio object for this article request
135
136 =cut
137
138 sub biblio {
139     my ($self) = @_;
140
141     $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
142
143     return $self->{_biblio};
144 }
145
146 =head3 item
147
148 Returns the Koha::Item object for this article request
149
150 =cut
151
152 sub item {
153     my ($self) = @_;
154
155     $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
156
157     return $self->{_item};
158 }
159
160 =head3 borrower
161
162 Returns the Koha::Patron object for this article request
163
164 =cut
165
166 sub borrower {
167     my ($self) = @_;
168
169     $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
170
171     return $self->{_borrower};
172 }
173
174 =head3 branch
175
176 Returns the Koha::Library object for this article request
177
178 =cut
179
180 sub branch {
181     my ($self) = @_;
182
183     $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
184
185     return $self->{_branch};
186 }
187
188 =head3 store
189
190 Override the default store behavior so that new opac requests
191 will have notifications sent.
192
193 =cut
194
195 sub store {
196     my ($self) = @_;
197     if ( $self->in_storage ) {
198         return $self->SUPER::store;
199     } else {
200         $self->created_on( dt_from_string() );
201         return $self->open;
202     }
203 }
204
205 =head3 _type
206
207 =cut
208
209 sub _type {
210     return 'ArticleRequest';
211 }
212
213 =head1 AUTHOR
214
215 Kyle M Hall <kyle@bywatersolutions.com>
216
217 =cut
218
219 1;