Bug 5087: (QA follow-up) used_for deserves an index
[koha.git] / Koha / ArticleRequest.pm
blob2c47dd03febb19ec3053be5d9466c91741dcf172
1 package Koha::ArticleRequest;
3 # Copyright ByWater Solutions 2015
5 # This file is part of Koha.
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.
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.
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>.
20 use Modern::Perl;
22 use Carp;
24 use Koha::Database;
25 use Koha::Patrons;
26 use Koha::Biblios;
27 use Koha::Items;
28 use Koha::Libraries;
29 use Koha::DateUtils qw(dt_from_string);
31 use base qw(Koha::Object);
33 =head1 NAME
35 Koha::ArticleRequest - Koha Article Request Object class
37 =head1 API
39 =head2 Class Methods
41 =cut
43 =head3 open
45 =cut
47 sub open {
48 my ($self) = @_;
50 $self->status(Koha::ArticleRequest::Status::Pending);
51 $self->SUPER::store();
52 $self->notify();
53 return $self;
56 =head3 process
58 =cut
60 sub process {
61 my ($self) = @_;
63 $self->status(Koha::ArticleRequest::Status::Processing);
64 $self->store();
65 $self->notify();
66 return $self;
69 =head3 complete
71 =cut
73 sub complete {
74 my ($self) = @_;
76 $self->status(Koha::ArticleRequest::Status::Completed);
77 $self->store();
78 $self->notify();
79 return $self;
82 =head3 cancel
84 =cut
86 sub cancel {
87 my ( $self, $notes ) = @_;
89 $self->status(Koha::ArticleRequest::Status::Canceled);
90 $self->notes($notes) if $notes;
91 $self->store();
92 $self->notify();
93 return $self;
96 =head3 notify
98 =cut
100 sub notify {
101 my ($self) = @_;
103 my $status = $self->status;
105 require C4::Letters;
106 if (
107 my $letter = C4::Letters::GetPreparedLetter(
108 module => 'circulation',
109 letter_code => "AR_$status", # AR_PENDING, AR_PROCESSING, AR_COMPLETED, AR_CANCELED
110 message_transport_type => 'email',
111 lang => $self->borrower->lang,
112 tables => {
113 article_requests => $self->id,
114 borrowers => $self->borrowernumber,
115 biblio => $self->biblionumber,
116 biblioitems => $self->biblionumber,
117 items => $self->itemnumber,
118 branches => $self->branchcode,
123 C4::Letters::EnqueueLetter(
125 letter => $letter,
126 borrowernumber => $self->borrowernumber,
127 message_transport_type => 'email',
129 ) or warn "can't enqueue letter $letter";
133 =head3 biblio
135 Returns the Koha::Biblio object for this article request
137 =cut
139 sub biblio {
140 my ($self) = @_;
142 $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );
144 return $self->{_biblio};
147 =head3 item
149 Returns the Koha::Item object for this article request
151 =cut
153 sub item {
154 my ($self) = @_;
156 $self->{_item} ||= Koha::Items->find( $self->itemnumber() );
158 return $self->{_item};
161 =head3 borrower
163 Returns the Koha::Patron object for this article request
165 =cut
167 sub borrower {
168 my ($self) = @_;
170 $self->{_borrower} ||= Koha::Patrons->find( $self->borrowernumber() );
172 return $self->{_borrower};
175 =head3 branch
177 Returns the Koha::Library object for this article request
179 =cut
181 sub branch {
182 my ($self) = @_;
184 $self->{_branch} ||= Koha::Libraries->find( $self->branchcode() );
186 return $self->{_branch};
189 =head3 store
191 Override the default store behavior so that new opac requests
192 will have notifications sent.
194 =cut
196 sub store {
197 my ($self) = @_;
198 if ( $self->in_storage ) {
199 return $self->SUPER::store;
200 } else {
201 $self->created_on( dt_from_string() );
202 return $self->open;
206 =head3 _type
208 =cut
210 sub _type {
211 return 'ArticleRequest';
214 =head1 AUTHOR
216 Kyle M Hall <kyle@bywatersolutions.com>
218 =cut