110 lines
3.4 KiB
PHP
110 lines
3.4 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");
|
|
}
|
|
|
|
$JSGlobals = ["BASE_URL" => self::getUrl("Domain"),
|
|
"DASHBOARD_URL" => self::getUrl("Dashboard"),
|
|
"MFAPPNAME" => MFAPPNAME_SLUG,
|
|
"PAGE_TITLE" => "Historische Tickets",
|
|
"PATH" => [
|
|
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
|
|
["text" => "Historische Tickets", "href" => self::getUrl("HistoricTicket")]
|
|
],
|
|
"HISTORIC_TICKET_API_URL" => self::getUrl("HistoricTicket/api"),
|
|
];
|
|
|
|
$this->layout()->set("vueViewName", "HistoricTicket");
|
|
$this->layout()->set("JSGlobals", $JSGlobals);
|
|
$this->layout()->setTemplate("VueViews/Vue");
|
|
}
|
|
|
|
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'] ?? [];
|
|
$order = $json['order'] ?? [];
|
|
$page = $json['pagination']['page'] ?? 1;
|
|
$perPage = $json['pagination']['per_page'] ?? 10;
|
|
|
|
$historicTickets = HistoricTicketModel::getAllHistoricTickets($filters, $perPage, ($page - 1) * $perPage, $order);
|
|
$filtered_available = HistoricTicketModel::countHistoricTickets($filters);
|
|
$totalRows = HistoricTicketModel::countHistoricTickets([]);
|
|
|
|
return [
|
|
"rows" => $historicTickets,
|
|
"pagination" => [
|
|
"page" => $page,
|
|
"total_pages" => ceil($filtered_available / $perPage),
|
|
"per_page" => $perPage,
|
|
"filtered_available" => intval($filtered_available),
|
|
"total_rows" => intval($totalRows)
|
|
]
|
|
];
|
|
}
|
|
|
|
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."
|
|
];
|
|
}
|
|
|
|
return HistoricTicketModel::findTicket($query);
|
|
}
|
|
} |