style: auto-fix 1340 phpcs PSR-12 violations via phpcbf; exclude MissingNamespace and SideEffects
This commit is contained in:
@@ -1,23 +1,28 @@
|
||||
<?php
|
||||
|
||||
require_once 'models/CommentModel.php';
|
||||
|
||||
class CommentController {
|
||||
class CommentController
|
||||
{
|
||||
private $commentModel;
|
||||
|
||||
public function __construct($conn) {
|
||||
|
||||
public function __construct($conn)
|
||||
{
|
||||
$this->commentModel = new CommentModel($conn);
|
||||
}
|
||||
|
||||
public function getCommentsByTicketId($ticketId) {
|
||||
|
||||
public function getCommentsByTicketId($ticketId)
|
||||
{
|
||||
return $this->commentModel->getCommentsByTicketId($ticketId);
|
||||
}
|
||||
|
||||
public function addComment($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');
|
||||
@@ -27,10 +32,10 @@ class CommentController {
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Add comment
|
||||
$result = $this->commentModel->addComment($ticketId, $data);
|
||||
|
||||
|
||||
// Return JSON response
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($result);
|
||||
@@ -40,4 +45,4 @@ class CommentController {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
require_once 'models/TicketModel.php';
|
||||
require_once 'models/UserPreferencesModel.php';
|
||||
require_once 'models/StatsModel.php';
|
||||
|
||||
class DashboardController {
|
||||
class DashboardController
|
||||
{
|
||||
private $ticketModel;
|
||||
private $prefsModel;
|
||||
private $statsModel;
|
||||
@@ -18,7 +20,8 @@ class DashboardController {
|
||||
/** Valid statuses */
|
||||
private const VALID_STATUSES = ['Open', 'Pending', 'In Progress', 'Closed'];
|
||||
|
||||
public function __construct($conn) {
|
||||
public function __construct($conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
$this->ticketModel = new TicketModel($conn);
|
||||
$this->prefsModel = new UserPreferencesModel($conn);
|
||||
@@ -28,7 +31,8 @@ class DashboardController {
|
||||
/**
|
||||
* Validate and sanitize a date string
|
||||
*/
|
||||
private function validateDate(?string $date): ?string {
|
||||
private function validateDate(?string $date): ?string
|
||||
{
|
||||
if (empty($date)) {
|
||||
return null;
|
||||
}
|
||||
@@ -42,7 +46,8 @@ class DashboardController {
|
||||
/**
|
||||
* Validate priority value (1-5)
|
||||
*/
|
||||
private function validatePriority($priority): ?int {
|
||||
private function validatePriority($priority): ?int
|
||||
{
|
||||
if ($priority === null || $priority === '') {
|
||||
return null;
|
||||
}
|
||||
@@ -53,7 +58,8 @@ class DashboardController {
|
||||
/**
|
||||
* Validate user ID
|
||||
*/
|
||||
private function validateUserId($userId): ?int {
|
||||
private function validateUserId($userId): ?int
|
||||
{
|
||||
if ($userId === null || $userId === '') {
|
||||
return null;
|
||||
}
|
||||
@@ -61,7 +67,8 @@ class DashboardController {
|
||||
return ($val > 0) ? $val : null;
|
||||
}
|
||||
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
// Get user ID for preferences
|
||||
$userId = isset($_SESSION['user']['user_id']) ? $_SESSION['user']['user_id'] : null;
|
||||
|
||||
@@ -73,7 +80,7 @@ class DashboardController {
|
||||
$limit = 15;
|
||||
if ($userId) {
|
||||
$limit = (int)$this->prefsModel->getPreference($userId, 'rows_per_page', 15);
|
||||
} else if (isset($_COOKIE['ticketsPerPage'])) {
|
||||
} elseif (isset($_COOKIE['ticketsPerPage'])) {
|
||||
$limit = (int)$_COOKIE['ticketsPerPage'];
|
||||
}
|
||||
$limit = max(1, min(100, $limit));
|
||||
@@ -98,11 +105,11 @@ class DashboardController {
|
||||
if (isset($_GET['status']) && !empty($_GET['status'])) {
|
||||
// Validate each status in the comma-separated list
|
||||
$requestedStatuses = array_map('trim', explode(',', $_GET['status']));
|
||||
$validStatuses = array_filter($requestedStatuses, function($s) {
|
||||
$validStatuses = array_filter($requestedStatuses, function ($s) {
|
||||
return in_array($s, self::VALID_STATUSES, true);
|
||||
});
|
||||
$status = !empty($validStatuses) ? implode(',', $validStatuses) : null;
|
||||
} else if (!isset($_GET['show_all'])) {
|
||||
} elseif (!isset($_GET['show_all'])) {
|
||||
// Get default status filters from user preferences
|
||||
if ($userId) {
|
||||
$status = $this->prefsModel->getPreference($userId, 'default_status_filters', 'Open,Pending,In Progress');
|
||||
@@ -124,24 +131,42 @@ class DashboardController {
|
||||
$closedFrom = $this->validateDate($_GET['closed_from'] ?? null);
|
||||
$closedTo = $this->validateDate($_GET['closed_to'] ?? null);
|
||||
|
||||
if ($createdFrom) $filters['created_from'] = $createdFrom;
|
||||
if ($createdTo) $filters['created_to'] = $createdTo;
|
||||
if ($updatedFrom) $filters['updated_from'] = $updatedFrom;
|
||||
if ($updatedTo) $filters['updated_to'] = $updatedTo;
|
||||
if ($closedFrom) $filters['closed_from'] = $closedFrom;
|
||||
if ($closedTo) $filters['closed_to'] = $closedTo;
|
||||
if ($createdFrom) {
|
||||
$filters['created_from'] = $createdFrom;
|
||||
}
|
||||
if ($createdTo) {
|
||||
$filters['created_to'] = $createdTo;
|
||||
}
|
||||
if ($updatedFrom) {
|
||||
$filters['updated_from'] = $updatedFrom;
|
||||
}
|
||||
if ($updatedTo) {
|
||||
$filters['updated_to'] = $updatedTo;
|
||||
}
|
||||
if ($closedFrom) {
|
||||
$filters['closed_from'] = $closedFrom;
|
||||
}
|
||||
if ($closedTo) {
|
||||
$filters['closed_to'] = $closedTo;
|
||||
}
|
||||
|
||||
// Validate priority filters; ?priority=N sets exact match (min=max=N)
|
||||
$prioritySingle = $this->validatePriority($_GET['priority'] ?? null);
|
||||
$priorityMin = $prioritySingle ?? $this->validatePriority($_GET['priority_min'] ?? null);
|
||||
$priorityMax = $prioritySingle ?? $this->validatePriority($_GET['priority_max'] ?? null);
|
||||
|
||||
if ($priorityMin !== null) $filters['priority_min'] = $priorityMin;
|
||||
if ($priorityMax !== null) $filters['priority_max'] = $priorityMax;
|
||||
if ($priorityMin !== null) {
|
||||
$filters['priority_min'] = $priorityMin;
|
||||
}
|
||||
if ($priorityMax !== null) {
|
||||
$filters['priority_max'] = $priorityMax;
|
||||
}
|
||||
|
||||
// Validate user ID filters
|
||||
$createdBy = $this->validateUserId($_GET['created_by'] ?? null);
|
||||
if ($createdBy !== null) $filters['created_by'] = $createdBy;
|
||||
if ($createdBy !== null) {
|
||||
$filters['created_by'] = $createdBy;
|
||||
}
|
||||
|
||||
// assigned_to accepts a numeric user ID, 'unassigned', or the special string 'me'
|
||||
$assignedToRaw = $_GET['assigned_to'] ?? null;
|
||||
@@ -151,7 +176,9 @@ class DashboardController {
|
||||
$filters['assigned_to'] = (int)$userId;
|
||||
} else {
|
||||
$assignedTo = $this->validateUserId($assignedToRaw);
|
||||
if ($assignedTo !== null) $filters['assigned_to'] = $assignedTo;
|
||||
if ($assignedTo !== null) {
|
||||
$filters['assigned_to'] = $assignedTo;
|
||||
}
|
||||
}
|
||||
|
||||
// Get tickets with pagination, sorting, search, and advanced filters
|
||||
@@ -161,7 +188,7 @@ class DashboardController {
|
||||
$filterOptions = $this->getCategoriesAndTypes();
|
||||
$categories = $filterOptions['categories'];
|
||||
$types = $filterOptions['types'];
|
||||
|
||||
|
||||
// Extract data for the view
|
||||
$tickets = $result['tickets'];
|
||||
$totalTickets = $result['total'];
|
||||
@@ -179,7 +206,8 @@ class DashboardController {
|
||||
*
|
||||
* @return array ['categories' => [...], 'types' => [...]]
|
||||
*/
|
||||
private function getCategoriesAndTypes(): array {
|
||||
private function getCategoriesAndTypes(): array
|
||||
{
|
||||
$sql = "SELECT 'category' as field, category as value FROM tickets WHERE category IS NOT NULL
|
||||
UNION
|
||||
SELECT 'type' as field, type as value FROM tickets WHERE type IS NOT NULL
|
||||
@@ -203,6 +231,4 @@ class DashboardController {
|
||||
|
||||
return ['categories' => $categories, 'types' => $types];
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
// Use absolute paths for model includes
|
||||
require_once dirname(__DIR__) . '/models/TicketModel.php';
|
||||
require_once dirname(__DIR__) . '/models/CommentModel.php';
|
||||
@@ -9,7 +10,8 @@ require_once dirname(__DIR__) . '/models/TemplateModel.php';
|
||||
require_once dirname(__DIR__) . '/helpers/UrlHelper.php';
|
||||
require_once dirname(__DIR__) . '/helpers/NotificationHelper.php';
|
||||
|
||||
class TicketController {
|
||||
class TicketController
|
||||
{
|
||||
private $ticketModel;
|
||||
private $commentModel;
|
||||
private $auditLogModel;
|
||||
@@ -18,7 +20,8 @@ class TicketController {
|
||||
private $templateModel;
|
||||
private $conn;
|
||||
|
||||
public function __construct($conn) {
|
||||
public function __construct($conn)
|
||||
{
|
||||
$this->conn = $conn;
|
||||
$this->ticketModel = new TicketModel($conn);
|
||||
$this->commentModel = new CommentModel($conn);
|
||||
@@ -27,8 +30,9 @@ class TicketController {
|
||||
$this->workflowModel = new WorkflowModel($conn);
|
||||
$this->templateModel = new TemplateModel($conn);
|
||||
}
|
||||
|
||||
public function view($id) {
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
// Get current user
|
||||
$currentUser = $GLOBALS['currentUser'] ?? null;
|
||||
$userId = $currentUser['user_id'] ?? null;
|
||||
@@ -63,7 +67,8 @@ class TicketController {
|
||||
include dirname(__DIR__) . '/views/TicketView.php';
|
||||
}
|
||||
|
||||
public function create() {
|
||||
public function create()
|
||||
{
|
||||
// Get current user
|
||||
$currentUser = $GLOBALS['currentUser'] ?? null;
|
||||
$userId = $currentUser['user_id'] ?? null;
|
||||
@@ -154,6 +159,4 @@ class TicketController {
|
||||
include dirname(__DIR__) . '/views/CreateTicketView.php';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user