3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use base qw(Koha::Object);
24 use Koha::Ticket::Update;
25 use Koha::Ticket::Updates;
29 Koha::Ticket - Koha Ticket Object class
39 Return the patron who submitted this ticket
45 my $rs = $self->_result->reporter;
47 return Koha::Patron->_new_from_dbic($rs);
52 Return the patron who submitted this ticket
58 my $rs = $self->_result->assignee;
60 return Koha::Patron->_new_from_dbic($rs);
65 Return the user who resolved this ticket
71 my $rs = $self->_result->resolver;
73 return Koha::Patron->_new_from_dbic($rs) if $rs;
78 Return the biblio linked to this ticket
84 my $rs = $self->_result->biblio;
86 return Koha::Biblio->_new_from_dbic($rs);
91 Return any updates attached to this ticket
97 my $rs = $self->_result->ticket_updates;
99 return Koha::Ticket::Updates->_new_from_dbic($rs) if $rs;
109 my ( $self, $params ) = @_;
111 my $rs = $self->_result->add_to_ticket_updates($params)->discard_changes;
112 return Koha::Ticket::Update->_new_from_dbic($rs);
119 Overloaded I<store> method to trigger notices as required
126 my $is_new = !$self->in_storage;
127 $self = $self->SUPER::store;
131 # Send patron acknowledgement
132 my $acknowledgement_letter = C4::Letters::GetPreparedLetter(
133 module => 'catalogue',
134 letter_code => 'TICKET_ACKNOWLEDGE',
135 branchcode => $self->reporter->branchcode,
136 tables => { tickets => $self->id }
139 if ($acknowledgement_letter) {
140 my $acknowledgement_message_id = C4::Letters::EnqueueLetter(
142 letter => $acknowledgement_letter,
143 message_transport_type => 'email',
144 borrowernumber => $self->reporter_id,
147 C4::Letters::SendQueuedMessages( { message_id => $acknowledgement_message_id } )
148 if $acknowledgement_message_id;
151 # Notify cataloger by email
152 if ( $self->biblio_id && C4::Context->preference('CatalogerEmails') ) {
154 # notify the library if a notice exists
155 my $notify_letter = C4::Letters::GetPreparedLetter(
156 module => 'catalogue',
157 letter_code => 'TICKET_NOTIFY',
158 branchcode => $self->reporter->branchcode,
159 tables => { tickets => $self->id }
162 if ($notify_letter) {
163 my $message_id = C4::Letters::EnqueueLetter(
165 letter => $notify_letter,
166 message_transport_type => 'email',
168 C4::Context->preference('CatalogerEmails'),
169 reply_address => $self->reporter->notice_email_address,
172 C4::Letters::SendQueuedMessages( { message_id => $message_id } ) if $message_id;
180 =head2 Internal methods
184 =head3 to_api_mapping
186 This method returns the mapping for representing a Koha::Ticket object
192 return { id => 'ticket_id', };
200 my ( $self, $params ) = @_;
204 if ( defined $self->status ) {
205 my $av = Koha::AuthorisedValues->search(
207 category => 'TICKET_STATUS',
208 authorised_value => $self->status,
212 # Fall back to TICKET_RESOLUTION as needed
214 $av = Koha::AuthorisedValues->search(
216 category => 'TICKET_RESOLUTION',
217 authorised_value => $self->status,
225 ? $av->next->opac_description
229 $strings->{status} = {
230 category => 'TICKET_STATUS',