Fixed MAJOR bugs, currently at a semi-stable state
This commit is contained in:
@ -3,8 +3,10 @@ require_once 'models/TicketModel.php';
|
||||
|
||||
class DashboardController {
|
||||
private $ticketModel;
|
||||
private $conn;
|
||||
|
||||
public function __construct($conn) {
|
||||
$this->conn = $conn;
|
||||
$this->ticketModel = new TicketModel($conn);
|
||||
}
|
||||
|
||||
@ -12,12 +14,27 @@ class DashboardController {
|
||||
// Get query parameters
|
||||
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
$limit = isset($_COOKIE['ticketsPerPage']) ? (int)$_COOKIE['ticketsPerPage'] : 15;
|
||||
$status = isset($_GET['status']) ? $_GET['status'] : 'Open';
|
||||
$sortColumn = isset($_COOKIE['defaultSortColumn']) ? $_COOKIE['defaultSortColumn'] : 'ticket_id';
|
||||
$sortDirection = isset($_COOKIE['sortDirection']) ? $_COOKIE['sortDirection'] : 'desc';
|
||||
$sortColumn = isset($_GET['sort']) ? $_GET['sort'] : 'ticket_id';
|
||||
$sortDirection = isset($_GET['dir']) ? $_GET['dir'] : 'desc';
|
||||
$category = isset($_GET['category']) ? $_GET['category'] : null;
|
||||
$type = isset($_GET['type']) ? $_GET['type'] : null;
|
||||
|
||||
// Get tickets with pagination
|
||||
$result = $this->ticketModel->getAllTickets($page, $limit, $status, $sortColumn, $sortDirection);
|
||||
// Handle status filtering
|
||||
$status = null;
|
||||
if (isset($_GET['status']) && !empty($_GET['status'])) {
|
||||
$status = $_GET['status'];
|
||||
} else if (!isset($_GET['show_all'])) {
|
||||
// Default: show Open and In Progress (exclude Closed)
|
||||
$status = 'Open,In Progress';
|
||||
}
|
||||
// If $_GET['show_all'] exists or no status param with show_all, show all tickets (status = null)
|
||||
|
||||
// Get tickets with pagination and sorting
|
||||
$result = $this->ticketModel->getAllTickets($page, $limit, $status, $sortColumn, $sortDirection, $category, $type);
|
||||
|
||||
// Get categories and types for filters
|
||||
$categories = $this->getCategories();
|
||||
$types = $this->getTypes();
|
||||
|
||||
// Extract data for the view
|
||||
$tickets = $result['tickets'];
|
||||
@ -27,4 +44,25 @@ class DashboardController {
|
||||
// Load the dashboard view
|
||||
include 'views/DashboardView.php';
|
||||
}
|
||||
}
|
||||
|
||||
private function getCategories() {
|
||||
$sql = "SELECT DISTINCT category FROM tickets WHERE category IS NOT NULL ORDER BY category";
|
||||
$result = $this->conn->query($sql);
|
||||
$categories = [];
|
||||
while($row = $result->fetch_assoc()) {
|
||||
$categories[] = $row['category'];
|
||||
}
|
||||
return $categories;
|
||||
}
|
||||
|
||||
private function getTypes() {
|
||||
$sql = "SELECT DISTINCT type FROM tickets WHERE type IS NOT NULL ORDER BY type";
|
||||
$result = $this->conn->query($sql);
|
||||
$types = [];
|
||||
while($row = $result->fetch_assoc()) {
|
||||
$types[] = $row['type'];
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user