109 lines
3.6 KiB
PHP
109 lines
3.6 KiB
PHP
<?php
|
|
|
|
class VoiceCallHistoryController extends mfBaseController {
|
|
private User $me;
|
|
private string $VOICE_PORTAL_HOST = KOLMISOFT_API_HOST;
|
|
private string $VOICE_PORTAL_API_KEY = KOLMISOFT_API_KEY;
|
|
private string $VOICE_PORTAL_USERNAME = KOLMISOFT_API_USERNAME;
|
|
|
|
private KolmisoftMore $kolmisoftMore;
|
|
|
|
|
|
protected function init(): void {
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->layout()->set("me", $me);
|
|
$this->me = $me;
|
|
|
|
if (!$this->me->isAdmin()) {
|
|
$this->redirect("dashboard");
|
|
}
|
|
|
|
$this->kolmisoftMore = new KolmisoftMore($this->VOICE_PORTAL_HOST, $this->VOICE_PORTAL_API_KEY, $this->VOICE_PORTAL_USERNAME);
|
|
|
|
}
|
|
|
|
protected function indexAction(): void {
|
|
$JSGlobals = ["BASE_URL" => self::getUrl("Domain"),
|
|
"DASHBOARD_URL" => self::getUrl("Dashboard"),
|
|
"MFAPPNAME" => MFAPPNAME_SLUG,
|
|
"PAGE_TITLE" => "Voice Call History",
|
|
"PATH" => [
|
|
["text" => MFAPPNAME_SLUG, "href" => self::getUrl("Dashboard")],
|
|
["text" => "Voice Call History", "href" => self::getUrl("VoiceCallHistory")]
|
|
],
|
|
"VOICE_CALL_HISTORY_API_URL" => self::getUrl("VoiceCallHistory/api"),
|
|
];
|
|
|
|
$this->layout()->set("vueViewName", "VoiceCallHistory");
|
|
$this->layout()->set("JSGlobals", $JSGlobals);
|
|
$this->layout()->setTemplate("VueViews/Vue");
|
|
}
|
|
|
|
protected function apiAction() {
|
|
$do = $this->request->do;
|
|
|
|
if (!$this->me->isAdmin()) {
|
|
$this->redirect("dashboard");
|
|
}
|
|
|
|
switch ($do) {
|
|
case "getCalls":
|
|
$return = $this->getCalls();
|
|
break;
|
|
case "importCallsFromToday":
|
|
$return = $this->importCallsFromToday();
|
|
break;
|
|
default:
|
|
$return = false;
|
|
break;
|
|
}
|
|
|
|
if (!$return) {
|
|
$return = [
|
|
"status" => "error",
|
|
"message" => "Invalid request."
|
|
];
|
|
}
|
|
|
|
die(json_encode($return));
|
|
}
|
|
|
|
private function importCallsFromToday(): array {
|
|
$startDate = strtotime(date("Y-m-d 0:00:00"));
|
|
$endDate = strtotime(date("Y-m-d 23:59:59"));
|
|
|
|
$callHistory = $this->kolmisoftMore->getVoiceCallHistory($startDate, $endDate);
|
|
|
|
return VoiceCallHistoryModel::importCallsFromKolmisoft($callHistory);
|
|
}
|
|
|
|
private function getCalls(): 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;
|
|
|
|
if (isset($filters['start']['from']) && isset($filters['start']['to']) && is_numeric($filters['start']['to'])) {
|
|
$filters['start']['from'] += 7200;
|
|
$filters['start']['to'] += 7200;
|
|
}
|
|
|
|
$calls = VoiceCallHistoryModel::getVoiceCallHistory($filters, $perPage, $perPage * $page - $perPage, $order);
|
|
$filtered_available = VoiceCallHistoryModel::countVoiceCallHistory($filters);
|
|
$totalRows = VoiceCallHistoryModel::countVoiceCallHistory([]);
|
|
|
|
return [
|
|
"rows" => $calls,
|
|
"pagination" => [
|
|
"page" => $page,
|
|
"total_pages" => ceil($filtered_available / $perPage),
|
|
"per_page" => $perPage,
|
|
"filtered_available" => intval($filtered_available),
|
|
"total_rows" => intval($totalRows)
|
|
]
|
|
];
|
|
}
|
|
} |