| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Services\Tickets; |
| 4 |
|
| 5 |
use FluentSupport\App\Models\Conversation; |
| 6 |
|
| 7 |
class TicketService |
| 8 |
{ |
| 9 |
public function close($ticket, $person, $internalNote = '') |
| 10 |
{ |
| 11 |
if ($ticket->status != 'closed') { |
| 12 |
$ticket->status = 'closed'; |
| 13 |
$ticket->resolved_at = current_time('mysql'); |
| 14 |
$ticket->closed_by = $person->id; |
| 15 |
$ticket->total_close_time = current_time('timestamp') - strtotime($ticket->created_at); |
| 16 |
$ticket->save(); |
| 17 |
do_action('fluent_support/ticket_closed', $ticket, $person); |
| 18 |
do_action('fluent_support/ticket_closed_by_' . $person->person_type, $ticket, $person); |
| 19 |
|
| 20 |
if(!$internalNote) { |
| 21 |
$internalNote = __('Ticket has been closed', 'fluent-support'); |
| 22 |
} |
| 23 |
|
| 24 |
Conversation::create([ |
| 25 |
'ticket_id' => $ticket->id, |
| 26 |
'person_id' => $person->id, |
| 27 |
'conversation_type' => 'internal_info', |
| 28 |
'content' => $internalNote |
| 29 |
]); |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
return $ticket; |
| 34 |
} |
| 35 |
|
| 36 |
public function reopen($ticket, $person) |
| 37 |
{ |
| 38 |
if ($ticket->status == 'closed') { |
| 39 |
$ticket->status = 'active'; |
| 40 |
$ticket->waiting_since = current_time('mysql'); |
| 41 |
$ticket->save(); |
| 42 |
do_action('fluent_support/ticket_reopen', $ticket, $person); |
| 43 |
do_action('fluent_support/ticket_reopen_by_' . $person->person_type, $ticket, $person); |
| 44 |
Conversation::create([ |
| 45 |
'ticket_id' => $ticket->id, |
| 46 |
'person_id' => $person->id, |
| 47 |
'conversation_type' => 'internal_info', |
| 48 |
'content' => __('Ticket has been reopened', 'fluent-support') |
| 49 |
]); |
| 50 |
} |
| 51 |
|
| 52 |
return $person; |
| 53 |
} |
| 54 |
|
| 55 |
public function onAgentChange($ticket, $person){ |
| 56 |
Conversation::create([ |
| 57 |
'ticket_id' => $ticket->id, |
| 58 |
'person_id' => $person->id, |
| 59 |
'conversation_type' => 'internal_info', |
| 60 |
'content' => $ticket->agent->full_name !== $person->full_name ? |
| 61 |
__($person->full_name .' assign '. $ticket->agent->full_name .' in this ticket' , 'fluent-support') : |
| 62 |
__($person->full_name. ' assign this ticket to self', 'fluent-support') |
| 63 |
]); |
| 64 |
|
| 65 |
return $person; |
| 66 |
} |
| 67 |
} |
| 68 |
|