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 user who resolved this ticket
58 my $rs = $self->_result->resolver;
60 return Koha::Patron->_new_from_dbic($rs) if $rs;
65 Return the biblio linked to this ticket
71 my $rs = $self->_result->biblio;
73 return Koha::Biblio->_new_from_dbic($rs);
78 Return any updates attached to this ticket
84 my $rs = $self->_result->ticket_updates;
86 return Koha::Ticket::Updates->_new_from_dbic($rs) if $rs;
96 my ( $self, $params ) = @_;
98 my $rs = $self->_result->add_to_ticket_updates($params)->discard_changes;
99 return Koha::Ticket::Update->_new_from_dbic($rs);
106 Overloaded I<store> method to trigger notices as required
113 my $is_new = !$self->in_storage;
114 $self = $self->SUPER::store;
118 # Send patron acknowledgement
119 my $acknowledgement_letter = C4::Letters::GetPreparedLetter(
120 module => 'catalogue',
121 letter_code => 'TICKET_ACKNOWLEDGE',
122 branchcode => $self->reporter->branchcode,
123 tables => { tickets => $self->id }
126 if ($acknowledgement_letter) {
127 my $acknowledgement_message_id = C4::Letters::EnqueueLetter(
129 letter => $acknowledgement_letter,
130 message_transport_type => 'email',
131 borrowernumber => $self->reporter_id,
134 C4::Letters::SendQueuedMessages(
135 { message_id => $acknowledgement_message_id } );
138 # Notify cataloger by email
139 if ( $self->biblio_id && C4::Context->preference('CatalogerEmails') ) {
141 # notify the library if a notice exists
142 my $notify_letter = C4::Letters::GetPreparedLetter(
143 module => 'catalogue',
144 letter_code => 'TICKET_NOTIFY',
145 branchcode => $self->reporter->branchcode,
146 tables => { tickets => $self->id }
149 if ($notify_letter) {
150 my $message_id = C4::Letters::EnqueueLetter(
152 letter => $notify_letter,
153 message_transport_type => 'email',
155 C4::Context->preference('CatalogerEmails'),
156 reply_address => $self->reporter->notice_email_address,
159 C4::Letters::SendQueuedMessages(
160 { message_id => $message_id } );
168 =head2 Internal methods
172 =head3 to_api_mapping
174 This method returns the mapping for representing a Koha::Ticket object
180 return { id => 'ticket_id', };