better filtering and searching
This commit is contained in:
@@ -46,15 +46,15 @@ class TicketModel {
|
||||
return $comments;
|
||||
}
|
||||
|
||||
public function getAllTickets($page = 1, $limit = 15, $status = 'Open', $sortColumn = 'ticket_id', $sortDirection = 'desc', $category = null, $type = null, $search = null) {
|
||||
public function getAllTickets($page = 1, $limit = 15, $status = 'Open', $sortColumn = 'ticket_id', $sortDirection = 'desc', $category = null, $type = null, $search = null, $filters = []) {
|
||||
// Calculate offset
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
|
||||
// Build WHERE clause
|
||||
$whereConditions = [];
|
||||
$params = [];
|
||||
$paramTypes = '';
|
||||
|
||||
|
||||
// Status filtering
|
||||
if ($status) {
|
||||
$statuses = explode(',', $status);
|
||||
@@ -63,7 +63,7 @@ class TicketModel {
|
||||
$params = array_merge($params, $statuses);
|
||||
$paramTypes .= str_repeat('s', count($statuses));
|
||||
}
|
||||
|
||||
|
||||
// Category filtering
|
||||
if ($category) {
|
||||
$categories = explode(',', $category);
|
||||
@@ -72,7 +72,7 @@ class TicketModel {
|
||||
$params = array_merge($params, $categories);
|
||||
$paramTypes .= str_repeat('s', count($categories));
|
||||
}
|
||||
|
||||
|
||||
// Type filtering
|
||||
if ($type) {
|
||||
$types = explode(',', $type);
|
||||
@@ -81,7 +81,7 @@ class TicketModel {
|
||||
$params = array_merge($params, $types);
|
||||
$paramTypes .= str_repeat('s', count($types));
|
||||
}
|
||||
|
||||
|
||||
// Search Functionality
|
||||
if ($search && !empty($search)) {
|
||||
$whereConditions[] = "(title LIKE ? OR description LIKE ? OR ticket_id LIKE ? OR category LIKE ? OR type LIKE ?)";
|
||||
@@ -89,6 +89,61 @@ class TicketModel {
|
||||
$params = array_merge($params, [$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm]);
|
||||
$paramTypes .= 'sssss';
|
||||
}
|
||||
|
||||
// Advanced search filters
|
||||
// Date range - created_at
|
||||
if (!empty($filters['created_from'])) {
|
||||
$whereConditions[] = "DATE(t.created_at) >= ?";
|
||||
$params[] = $filters['created_from'];
|
||||
$paramTypes .= 's';
|
||||
}
|
||||
if (!empty($filters['created_to'])) {
|
||||
$whereConditions[] = "DATE(t.created_at) <= ?";
|
||||
$params[] = $filters['created_to'];
|
||||
$paramTypes .= 's';
|
||||
}
|
||||
|
||||
// Date range - updated_at
|
||||
if (!empty($filters['updated_from'])) {
|
||||
$whereConditions[] = "DATE(t.updated_at) >= ?";
|
||||
$params[] = $filters['updated_from'];
|
||||
$paramTypes .= 's';
|
||||
}
|
||||
if (!empty($filters['updated_to'])) {
|
||||
$whereConditions[] = "DATE(t.updated_at) <= ?";
|
||||
$params[] = $filters['updated_to'];
|
||||
$paramTypes .= 's';
|
||||
}
|
||||
|
||||
// Priority range
|
||||
if (!empty($filters['priority_min'])) {
|
||||
$whereConditions[] = "t.priority >= ?";
|
||||
$params[] = (int)$filters['priority_min'];
|
||||
$paramTypes .= 'i';
|
||||
}
|
||||
if (!empty($filters['priority_max'])) {
|
||||
$whereConditions[] = "t.priority <= ?";
|
||||
$params[] = (int)$filters['priority_max'];
|
||||
$paramTypes .= 'i';
|
||||
}
|
||||
|
||||
// Created by user
|
||||
if (!empty($filters['created_by'])) {
|
||||
$whereConditions[] = "t.created_by = ?";
|
||||
$params[] = (int)$filters['created_by'];
|
||||
$paramTypes .= 'i';
|
||||
}
|
||||
|
||||
// Assigned to user (including unassigned option)
|
||||
if (!empty($filters['assigned_to'])) {
|
||||
if ($filters['assigned_to'] === 'unassigned') {
|
||||
$whereConditions[] = "t.assigned_to IS NULL";
|
||||
} else {
|
||||
$whereConditions[] = "t.assigned_to = ?";
|
||||
$params[] = (int)$filters['assigned_to'];
|
||||
$paramTypes .= 'i';
|
||||
}
|
||||
}
|
||||
|
||||
$whereClause = '';
|
||||
if (!empty($whereConditions)) {
|
||||
|
||||
Reference in New Issue
Block a user