103 lines
2.8 KiB
PHP
103 lines
2.8 KiB
PHP
<?php
|
|
|
|
|
|
class HistoricTicketController extends mfBaseController {
|
|
private User $me;
|
|
|
|
protected function init(): void {
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->layout()->set("me", $me);
|
|
$this->me = $me;
|
|
}
|
|
|
|
protected function indexAction(): void {
|
|
if (!$this->me->is("employee")) {
|
|
$this->redirect("dashboard");
|
|
}
|
|
$this->layout()->setTemplate("HistoricTicket/Index");
|
|
}
|
|
|
|
protected function apiAction() {
|
|
$do = $this->request->do;
|
|
|
|
if ($do !== "getConfig" && !$this->me->is("employee")) {
|
|
$this->redirect("dashboard");
|
|
}
|
|
|
|
switch ($do) {
|
|
case "getHistoricTickets":
|
|
$return = $this->getHistoricTickets();
|
|
break;
|
|
case "getHistoricTicketMessages":
|
|
$return = $this->getHistoricTicketMessages();
|
|
break;
|
|
case "findHistoricTicket":
|
|
$return = $this->findHistoricTicket();
|
|
break;
|
|
default:
|
|
$return = false;
|
|
break;
|
|
}
|
|
|
|
if (!$return) {
|
|
$return = [
|
|
"status" => "error",
|
|
"message" => "Invalid request."
|
|
];
|
|
}
|
|
|
|
die(json_encode($return));
|
|
}
|
|
|
|
private function getHistoricTickets(): array {
|
|
$json = json_decode(file_get_contents('php://input'), true);
|
|
|
|
$filters = $json['filters'] ?? [];
|
|
$page = $json['pagination']['page'] ?? 1;
|
|
$perPage = $json['pagination']['per_page'] ?? 10;
|
|
|
|
$historicTickets = HistoricTicketModel::getAllHistoricTickets($filters, $perPage, ($page - 1) * $perPage);
|
|
$total = HistoricTicketModel::countHistoricTickets($filters);
|
|
|
|
return [
|
|
"rows" => $historicTickets,
|
|
"pagination" => [
|
|
"page" => $page,
|
|
"total_pages" => ceil($total / $perPage),
|
|
"per_page" => $perPage,
|
|
"total_rows" => intval($total)
|
|
]
|
|
];
|
|
}
|
|
|
|
private function getHistoricTicketMessages(): array {
|
|
$json = json_decode(file_get_contents('php://input'), true);
|
|
$ticketNumber = $json['ticketNumber'];
|
|
|
|
return HistoricTicketModel::findHistoricTicket($ticketNumber);
|
|
}
|
|
|
|
private function findHistoricTicket(): array {
|
|
$query = $this->request->query;
|
|
|
|
if (empty($query)) {
|
|
return [
|
|
"status" => "error",
|
|
"message" => "No query provided."
|
|
];
|
|
}
|
|
|
|
$rows = HistoricTicketModel::findTicket($query);
|
|
|
|
return [
|
|
"rows" => $rows,
|
|
"pagination" => [
|
|
"page" => 1,
|
|
"total_pages" => 1,
|
|
"per_page" => count($rows),
|
|
"total_rows" => count($rows)
|
|
]
|
|
];
|
|
}
|
|
} |