Yii::$app->params["time"]) $this->redirect(["/dashboard"]); if (Yii::$app->user->isGuest) return $this->redirect(['/site/login']); } /** * {@inheritdoc} */ public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ]; } public function actionIndex() { $this->view->title = 'Theo dõi trực tuyến'; $deviceLists = Device::find()->all(); $devices = []; foreach ($deviceLists as $key => $value) { $devices[] = $value->ip_address; } common::requestToCardService("/GetRTLog/Start", [ "DeviceIPs" => implode(",", $devices) ]); return $this->render('index', [ ]); } public function actionData() { if (Yii::$app->request->post()) { $post = Yii::$app->request->post(); Yii::$app->response->format = "json"; $Device = Device::findOne(['ip_address' => $post['DeviceIP']]); $Door = false; if ($Device) $Door = Door::findOne(['device_id' => $Device->id, 'code' => $post['DoorNo']]); $EventType = EventType::eventTypeArray(); $Staff = Staff::findOne($post['StaffID']); $department = ""; if ($Staff) { $dept = Department::findOne($Staff->department_id); $department = $dept ? $dept->name : ""; } return [ "device" => $Device ? $Device->name : $post['DeviceIP'], "door" => $Door ? $Door->name : $post['DoorNo'], "eventType" => isset($EventType[$post['EventCode']]) ? $EventType[$post['EventCode']] : false, "staff_code" => $Staff ? $Staff->code : "", "staff_name" => $Staff ? $Staff->name : "", "staff_department" => $department ]; } } public function actionStop() { if (Yii::$app->request->isAjax) { return common::requestToCardService("/GetRTLog/Stop", []); } } }