conn = $conn; } public function getCommentsByTicketId($ticketId) { $sql = "SELECT * FROM ticket_comments WHERE ticket_id = ? ORDER BY created_at DESC"; $stmt = $this->conn->prepare($sql); $stmt->bind_param("s", $ticketId); // Changed to string since ticket_id is varchar $stmt->execute(); $result = $stmt->get_result(); $comments = []; while ($row = $result->fetch_assoc()) { $comments[] = $row; } return $comments; } public function addComment($ticketId, $commentData) { $sql = "INSERT INTO ticket_comments (ticket_id, user_name, comment_text, markdown_enabled) VALUES (?, ?, ?, ?)"; $stmt = $this->conn->prepare($sql); // Set default username $username = $commentData['user_name'] ?? 'User'; $markdownEnabled = isset($commentData['markdown_enabled']) && $commentData['markdown_enabled'] ? 1 : 0; // Preserve line breaks in the comment text $commentText = $commentData['comment_text']; $stmt->bind_param( "sssi", $ticketId, $username, $commentText, $markdownEnabled ); if ($stmt->execute()) { return [ 'success' => true, 'user_name' => $username, 'created_at' => date('M d, Y H:i'), 'markdown_enabled' => $markdownEnabled, 'comment_text' => $commentText ]; } else { return [ 'success' => false, 'error' => $this->conn->error ]; } } } ?>