[VoiceCallHistory]
- implemented VoiceCallHistoryJob for running the jobs - implement /VoiceCallHistory for displaying, importing the Voice Call History - added date-range-picker to tt-table (still todo)
This commit is contained in:
96
application/VoiceCallHistory/VoiceCallHistoryController.php
Normal file
96
application/VoiceCallHistory/VoiceCallHistoryController.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
//display errors
|
||||
//ini_set('display_errors', 1);
|
||||
//ini_set('display_startup_errors', 1);
|
||||
//error_reporting(E_ALL);
|
||||
|
||||
class VoiceCallHistoryController extends mfBaseController {
|
||||
private User $me;
|
||||
private string $VOICE_PORTAL_HOST = "vportal.xinon.at";
|
||||
private string $VOICE_PORTAL_API_KEY = "2f9mpw3oamALg7gSgtWUTCKNZ01fFRDh";
|
||||
private string $VOICE_PORTAL_USERNAME = "700342020";
|
||||
|
||||
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 {
|
||||
$this->layout()->setTemplate("VoiceCallHistory/Index");
|
||||
}
|
||||
|
||||
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 8:00:00"));
|
||||
$endDate = strtotime(date("Y-m-d 9:00: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'] ?? [];
|
||||
$page = $json['pagination']['page'] ?? 1;
|
||||
$perPage = $json['pagination']['per_page'] ?? 10;
|
||||
|
||||
$calls = VoiceCallHistoryModel::getVoiceCallHistory($filters, $perPage, $perPage * $page - $perPage);
|
||||
$totalRows = VoiceCallHistoryModel::countVoiceCallHistory($filters);
|
||||
|
||||
return [
|
||||
"rows" => $calls,
|
||||
"pagination" => [
|
||||
"page" => $page,
|
||||
"total_pages" => ceil($totalRows / $perPage),
|
||||
"per_page" => $perPage,
|
||||
"total_rows" => intval($totalRows)
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user