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 = 'Cấp quyền truy cập'; return $this->render('index', [ "company" => Department::findOne(1), "scheduleArray" => Schedule::scheduleArray(), "doorLists" => Door::find()->all(), "deviceArray" => Device::deviceArray() ]); } public function actionStaff($id) { if (Yii::$app->request->isAjax) { $model = new Department(); $lsDepartment = $model->departmentChilds(intval($id)); return $this->renderPartial("staff", [ "departmentArray" => Department::departmentArray(), "scheduleArray" => Schedule::scheduleArray(), "staffs" => Staff::find()->andWhere(['IN', 'department_id', $lsDepartment])->all() ]); } } public function actionSearchStaff() { if (Yii::$app->request->post()) { $post = Yii::$app->request->post(); return $this->renderPartial("staff", [ "departmentArray" => Department::departmentArray(), "scheduleArray" => Schedule::scheduleArray(), "staffs" => Staff::find()->andWhere(['OR', ["LIKE", "name", $post['key']], ["LIKE", "code", $post['key']]])->all() ]); } } public function actionSetSchedule() { if (Yii::$app->request->post()) { $post = Yii::$app->request->post(); Staff::updateAll(["schedule_id" => $post["schedule"], "door_access" => json_encode($post["doors"])], ["IN", "id", $post["staffs"]]); $doors = []; foreach ($post["doors"] as $key => $value) { $doors[] = Door::findOne($value)->name; } Yii::$app->response->format = "json"; return [ "schedule" => Schedule::findOne($post['schedule'])->name, "doors" => implode(", ", $doors) ]; } } }