| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Actions\Controller\TicketActions; |
| 4 |
|
| 5 |
use SyncBasalam\Actions\Controller\ActionController; |
| 6 |
use SyncBasalam\Services\TicketServiceManager; |
| 7 |
use SyncBasalam\Utilities\TicketExtraInfoFormatter; |
| 8 |
|
| 9 |
defined('ABSPATH') || exit; |
| 10 |
|
| 11 |
class CreateTicketItem extends ActionController |
| 12 |
{ |
| 13 |
public function __invoke() |
| 14 |
{ |
| 15 |
$ticketManager = new TicketServiceManager(); |
| 16 |
|
| 17 |
$content = isset($_POST['content']) ? \sanitize_textarea_field(\wp_unslash($_POST['content'])) : ''; |
| 18 |
$content = TicketExtraInfoFormatter::appendFromRequest($content, $_POST); |
| 19 |
$ticketId = isset($_POST['ticket_id']) ? intval(\wp_unslash($_POST['ticket_id'])) : 0; |
| 20 |
|
| 21 |
if ($ticketId <= 0) return; |
| 22 |
|
| 23 |
$ticketResponse = $ticketManager->fetchTicket($ticketId); |
| 24 |
$ticket = isset($ticketResponse['body']) ? json_decode($ticketResponse['body'], true) : null; |
| 25 |
|
| 26 |
if (is_array($ticket) && TicketServiceManager::isTicketClosed($ticket)) return; |
| 27 |
|
| 28 |
$fileIds = isset($_POST['file_ids']) && is_array($_POST['file_ids']) |
| 29 |
? array_map('intval', $_POST['file_ids']) |
| 30 |
: []; |
| 31 |
|
| 32 |
$ticketManager->createTicketItem($ticketId, $content, $fileIds); |
| 33 |
} |
| 34 |
} |
| 35 |
|