mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-28 09:50:28 +02:00
Added view ticket
This commit is contained in:
parent
2795e814c2
commit
27f912ed1c
5 changed files with 196 additions and 115 deletions
|
@ -41,6 +41,7 @@ class SupportController extends Controller
|
|||
}
|
||||
|
||||
try {
|
||||
$db->beginTransaction();
|
||||
$currentDateTime = new \DateTime();
|
||||
$crdate = $currentDateTime->format('Y-m-d H:i:s.v');
|
||||
$db->insert(
|
||||
|
@ -62,17 +63,8 @@ class SupportController extends Controller
|
|||
]
|
||||
);
|
||||
$ticket_id = $db->getLastInsertId();
|
||||
|
||||
$db->insert(
|
||||
'ticket_responses',
|
||||
[
|
||||
'ticket_id' => $ticket_id,
|
||||
'responder_id' => $_SESSION['auth_user_id'],
|
||||
'response' => $message,
|
||||
'date_created' => $crdate,
|
||||
]
|
||||
);
|
||||
|
||||
$db->commit();
|
||||
} catch (Exception $e) {
|
||||
$db->rollBack();
|
||||
return view($response, 'admin/support/newticket.twig', [
|
||||
|
@ -96,6 +88,86 @@ class SupportController extends Controller
|
|||
'categories' => $categories,
|
||||
]);
|
||||
}
|
||||
|
||||
public function viewTicket(Request $request, Response $response, $args)
|
||||
{
|
||||
$rawNumber = $args;
|
||||
$ticketNumber = filter_var($rawNumber, FILTER_VALIDATE_INT);
|
||||
|
||||
if ($ticketNumber === false) {
|
||||
$this->container->get('flash')->addMessage('error', 'Invalid ticket number');
|
||||
return $response->withHeader('Location', '/support')->withStatus(302);
|
||||
}
|
||||
|
||||
$db = $this->container->get('db');
|
||||
// Get the current URI
|
||||
$uri = $request->getUri()->getPath();
|
||||
|
||||
$ticket = $db->selectRow('SELECT st.*, u.username AS ticket_creator
|
||||
FROM support_tickets AS st
|
||||
JOIN users AS u ON st.user_id = u.id
|
||||
WHERE st.id = ?', [$ticketNumber]);
|
||||
|
||||
if ($ticket) {
|
||||
$replies = $db->select('SELECT tr.*, u.username AS responder_name
|
||||
FROM ticket_responses AS tr
|
||||
JOIN users AS u ON tr.responder_id = u.id
|
||||
WHERE tr.ticket_id = ?', [$ticketNumber]);
|
||||
$category = $db->selectValue('SELECT name FROM ticket_categories WHERE id = ?', [$ticket['category_id']]);
|
||||
|
||||
// Default view for GET requests or if POST data is not set
|
||||
return view($response,'admin/support/viewTicket.twig', [
|
||||
'ticket' => $ticket,
|
||||
'replies' => $replies,
|
||||
'category' => $category,
|
||||
'currentUri' => $uri
|
||||
]);
|
||||
} else {
|
||||
$this->container->get('flash')->addMessage('error', 'Invalid ticket number');
|
||||
return $response->withHeader('Location', '/support')->withStatus(302);
|
||||
}
|
||||
}
|
||||
|
||||
public function replyTicket(Request $request, Response $response)
|
||||
{
|
||||
if ($request->getMethod() === 'POST') {
|
||||
// Retrieve POST data
|
||||
$data = $request->getParsedBody();
|
||||
$db = $this->container->get('db');
|
||||
// Get the current URI
|
||||
$uri = $request->getUri()->getPath();
|
||||
$categories = $db->select("SELECT * FROM ticket_categories");
|
||||
|
||||
$ticket_id = $data['ticket_id'] ?? null;
|
||||
$responseText = $data['responseText'] ?? null;
|
||||
|
||||
if (!$responseText) {
|
||||
$this->container->get('flash')->addMessage('error', 'Please enter a reply');
|
||||
return $response->withHeader('Location', '/ticket/'.$ticket_id)->withStatus(302);
|
||||
}
|
||||
|
||||
try {
|
||||
$currentDateTime = new \DateTime();
|
||||
$crdate = $currentDateTime->format('Y-m-d H:i:s.v');
|
||||
|
||||
$db->insert(
|
||||
'ticket_responses',
|
||||
[
|
||||
'ticket_id' => $ticket_id,
|
||||
'responder_id' => $_SESSION['auth_user_id'],
|
||||
'response' => $responseText,
|
||||
'date_created' => $crdate,
|
||||
]
|
||||
);
|
||||
|
||||
$this->container->get('flash')->addMessage('success', 'Reply has been created successfully on ' . $crdate);
|
||||
return $response->withHeader('Location', '/ticket/'.$ticket_id)->withStatus(302);
|
||||
} catch (Exception $e) {
|
||||
$this->container->get('flash')->addMessage('error', 'Database error: '.$e->getMessage());
|
||||
return $response->withHeader('Location', '/ticket/'.$ticket_id)->withStatus(302);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function docs(Request $request, Response $response)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue