121 lines
3.4 KiB
PHP
121 lines
3.4 KiB
PHP
|
|
<?php
|
||
|
|
/**
|
||
|
|
* TemplateModel - Handles ticket template operations
|
||
|
|
*/
|
||
|
|
class TemplateModel {
|
||
|
|
private $conn;
|
||
|
|
|
||
|
|
public function __construct($conn) {
|
||
|
|
$this->conn = $conn;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get all active templates
|
||
|
|
*
|
||
|
|
* @return array Array of template records
|
||
|
|
*/
|
||
|
|
public function getAllTemplates() {
|
||
|
|
$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
|
||
|
|
*/
|
||
|
|
public function getTemplateById($templateId) {
|
||
|
|
$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
|
||
|
|
*/
|
||
|
|
public function createTemplate($data, $createdBy) {
|
||
|
|
$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
|
||
|
|
*/
|
||
|
|
public function updateTemplate($templateId, $data) {
|
||
|
|
$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
|
||
|
|
*/
|
||
|
|
public function deactivateTemplate($templateId) {
|
||
|
|
$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;
|
||
|
|
}
|
||
|
|
}
|