Files
jared c90bdc8ac8
Lint / PHP (phpcs PSR-12) (push) Failing after 29s
Lint / JS (eslint) (push) Successful in 12s
style: auto-fix 1340 phpcs PSR-12 violations via phpcbf; exclude MissingNamespace and SideEffects
2026-04-13 20:56:10 -04:00

49 lines
1.3 KiB
PHP

<?php
require_once 'models/CommentModel.php';
class CommentController
{
private $commentModel;
public function __construct($conn)
{
$this->commentModel = new CommentModel($conn);
}
public function getCommentsByTicketId($ticketId)
{
return $this->commentModel->getCommentsByTicketId($ticketId);
}
public function addComment($ticketId)
{
// Check if this is an AJAX request
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get JSON data
$data = json_decode(file_get_contents('php://input'), true);
// Validate input
if (empty($data['comment_text'])) {
header('Content-Type: application/json');
echo json_encode([
'success' => false,
'error' => 'Comment text cannot be empty'
]);
return;
}
// Add comment
$result = $this->commentModel->addComment($ticketId, $data);
// Return JSON response
header('Content-Type: application/json');
echo json_encode($result);
} else {
// For direct access, redirect to ticket view
header("Location: /tinkertickets/ticket/$ticketId");
exit;
}
}
}