Re-did everything, Now is modulaar and better bro.
This commit is contained in:
43
controllers/CommentController.php
Normal file
43
controllers/CommentController.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user