2026-01-01 19:00:42 -05:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* TemplateModel - Handles ticket template operations
|
|
|
|
|
*/
|
|
|
|
|
class TemplateModel {
|
Add PHP 7.4+ type hints to helpers, models, and middleware
Added strict typing with parameter types, return types, and property
types across all core classes:
- helpers: Database, ErrorHandler, CacheHelper
- models: TicketModel, UserModel, WorkflowModel, TemplateModel, UserPreferencesModel
- middleware: RateLimitMiddleware, CsrfMiddleware, SecurityHeadersMiddleware
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 11:04:36 -05:00
|
|
|
private mysqli $conn;
|
2026-01-01 19:00:42 -05:00
|
|
|
|
Add PHP 7.4+ type hints to helpers, models, and middleware
Added strict typing with parameter types, return types, and property
types across all core classes:
- helpers: Database, ErrorHandler, CacheHelper
- models: TicketModel, UserModel, WorkflowModel, TemplateModel, UserPreferencesModel
- middleware: RateLimitMiddleware, CsrfMiddleware, SecurityHeadersMiddleware
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 11:04:36 -05:00
|
|
|
public function __construct(mysqli $conn) {
|
2026-01-01 19:00:42 -05:00
|
|
|
$this->conn = $conn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all active templates
|
|
|
|
|
*
|
|
|
|
|
* @return array Array of template records
|
|
|
|
|
*/
|
Add PHP 7.4+ type hints to helpers, models, and middleware
Added strict typing with parameter types, return types, and property
types across all core classes:
- helpers: Database, ErrorHandler, CacheHelper
- models: TicketModel, UserModel, WorkflowModel, TemplateModel, UserPreferencesModel
- middleware: RateLimitMiddleware, CsrfMiddleware, SecurityHeadersMiddleware
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 11:04:36 -05:00
|
|
|
public function getAllTemplates(): array {
|
2026-01-01 19:00:42 -05:00
|
|
|
$sql = "SELECT * FROM ticket_templates WHERE is_active = TRUE ORDER BY template_name";
|
|
|
|
|
$result = $this->conn->query($sql);
|
|
|
|
|
|
|
|
|
|
$templates = [];
|
|
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
|
$templates[] = $row;
|
|
|
|
|
}
|
|
|
|
|
return $templates;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get template by ID
|
|
|
|
|
*
|
|
|
|
|
* @param int $templateId Template ID
|
|
|
|
|
* @return array|null Template record or null if not found
|
|
|
|
|
*/
|
Add PHP 7.4+ type hints to helpers, models, and middleware
Added strict typing with parameter types, return types, and property
types across all core classes:
- helpers: Database, ErrorHandler, CacheHelper
- models: TicketModel, UserModel, WorkflowModel, TemplateModel, UserPreferencesModel
- middleware: RateLimitMiddleware, CsrfMiddleware, SecurityHeadersMiddleware
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 11:04:36 -05:00
|
|
|
public function getTemplateById(int $templateId): ?array {
|
2026-01-01 19:00:42 -05:00
|
|
|
$sql = "SELECT * FROM ticket_templates WHERE template_id = ? AND is_active = TRUE";
|
|
|
|
|
$stmt = $this->conn->prepare($sql);
|
|
|
|
|
$stmt->bind_param("i", $templateId);
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
$result = $stmt->get_result();
|
|
|
|
|
|
|
|
|
|
$template = $result->fetch_assoc();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
return $template;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new template
|
|
|
|
|
*
|
|
|
|
|
* @param array $data Template data
|
|
|
|
|
* @param int $createdBy User ID creating the template
|
|
|
|
|
* @return bool Success status
|
|
|
|
|
*/
|
Add PHP 7.4+ type hints to helpers, models, and middleware
Added strict typing with parameter types, return types, and property
types across all core classes:
- helpers: Database, ErrorHandler, CacheHelper
- models: TicketModel, UserModel, WorkflowModel, TemplateModel, UserPreferencesModel
- middleware: RateLimitMiddleware, CsrfMiddleware, SecurityHeadersMiddleware
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 11:04:36 -05:00
|
|
|
public function createTemplate(array $data, int $createdBy): bool {
|
2026-01-01 19:00:42 -05:00
|
|
|
$sql = "INSERT INTO ticket_templates (template_name, title_template, description_template,
|
|
|
|
|
category, type, default_priority, created_by)
|
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
|
$stmt = $this->conn->prepare($sql);
|
|
|
|
|
$stmt->bind_param("sssssii",
|
|
|
|
|
$data['template_name'],
|
|
|
|
|
$data['title_template'],
|
|
|
|
|
$data['description_template'],
|
|
|
|
|
$data['category'],
|
|
|
|
|
$data['type'],
|
|
|
|
|
$data['default_priority'],
|
|
|
|
|
$createdBy
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update an existing template
|
|
|
|
|
*
|
|
|
|
|
* @param int $templateId Template ID
|
|
|
|
|
* @param array $data Template data to update
|
|
|
|
|
* @return bool Success status
|
|
|
|
|
*/
|
Add PHP 7.4+ type hints to helpers, models, and middleware
Added strict typing with parameter types, return types, and property
types across all core classes:
- helpers: Database, ErrorHandler, CacheHelper
- models: TicketModel, UserModel, WorkflowModel, TemplateModel, UserPreferencesModel
- middleware: RateLimitMiddleware, CsrfMiddleware, SecurityHeadersMiddleware
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 11:04:36 -05:00
|
|
|
public function updateTemplate(int $templateId, array $data): bool {
|
2026-01-01 19:00:42 -05:00
|
|
|
$sql = "UPDATE ticket_templates SET
|
|
|
|
|
template_name = ?,
|
|
|
|
|
title_template = ?,
|
|
|
|
|
description_template = ?,
|
|
|
|
|
category = ?,
|
|
|
|
|
type = ?,
|
|
|
|
|
default_priority = ?
|
|
|
|
|
WHERE template_id = ?";
|
|
|
|
|
$stmt = $this->conn->prepare($sql);
|
|
|
|
|
$stmt->bind_param("ssssiii",
|
|
|
|
|
$data['template_name'],
|
|
|
|
|
$data['title_template'],
|
|
|
|
|
$data['description_template'],
|
|
|
|
|
$data['category'],
|
|
|
|
|
$data['type'],
|
|
|
|
|
$data['default_priority'],
|
|
|
|
|
$templateId
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deactivate a template (soft delete)
|
|
|
|
|
*
|
|
|
|
|
* @param int $templateId Template ID
|
|
|
|
|
* @return bool Success status
|
|
|
|
|
*/
|
Add PHP 7.4+ type hints to helpers, models, and middleware
Added strict typing with parameter types, return types, and property
types across all core classes:
- helpers: Database, ErrorHandler, CacheHelper
- models: TicketModel, UserModel, WorkflowModel, TemplateModel, UserPreferencesModel
- middleware: RateLimitMiddleware, CsrfMiddleware, SecurityHeadersMiddleware
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 11:04:36 -05:00
|
|
|
public function deactivateTemplate(int $templateId): bool {
|
2026-01-01 19:00:42 -05:00
|
|
|
$sql = "UPDATE ticket_templates SET is_active = FALSE WHERE template_id = ?";
|
|
|
|
|
$stmt = $this->conn->prepare($sql);
|
|
|
|
|
$stmt->bind_param("i", $templateId);
|
|
|
|
|
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
}
|