118 lines
4.0 KiB
PHP
118 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace app\controllers;
|
|
|
|
use Yii;
|
|
use app\models\Department;
|
|
use app\models\Staff;
|
|
use app\models\Schedule;
|
|
use app\models\Door;
|
|
use app\models\Device;
|
|
use yii\web\Controller;
|
|
use yii\filters\VerbFilter;
|
|
use app\models\StaffSearch;
|
|
|
|
/**
|
|
* DeviceController implements the CRUD actions for Device model.
|
|
*/
|
|
class AssignController extends Controller {
|
|
|
|
public function init() {
|
|
parent::init();
|
|
if (time() > 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() {
|
|
if (!Yii::$app->user->can("scheduleAssign"))
|
|
throw new \yii\web\HttpException(403, 'Bạn không có quyền truy cập nội dung này');
|
|
|
|
$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));
|
|
|
|
$searchModel = new StaffSearch();
|
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
|
$dataProvider->query->andFilterWhere(['IN', 'department_id', $lsDepartment]);
|
|
$dataProvider->pagination->pageSize = 200;
|
|
|
|
return $this->renderAjax("staff", [
|
|
'searchModel' => $searchModel,
|
|
'dataProvider' => $dataProvider,
|
|
"departmentArray" => Department::departmentArray(),
|
|
"scheduleArray" => Schedule::scheduleArray(),
|
|
"doorsArray" => Door::doorsArray()
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function actionSearchStaff() {
|
|
if (Yii::$app->request->post()) {
|
|
$post = Yii::$app->request->post();
|
|
$searchModel = new StaffSearch();
|
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
|
$dataProvider->query->andFilterWhere(['OR', ["LIKE", "name", $post['key']], ["LIKE", "code", $post['key']]]);
|
|
$dataProvider->pagination->pageSize = 200;
|
|
|
|
return $this->renderAjax("staff", [
|
|
'searchModel' => $searchModel,
|
|
'dataProvider' => $dataProvider,
|
|
"departmentArray" => Department::departmentArray(),
|
|
"scheduleArray" => Schedule::scheduleArray(),
|
|
"doorsArray" => Door::doorsArray()
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function actionSetSchedule() {
|
|
if (Yii::$app->request->post()) {
|
|
$post = Yii::$app->request->post();
|
|
$lists = Staff::find()->andWhere(["IN", "id", $post["staffs"]])->all();
|
|
foreach ($lists as $key => $value) {
|
|
$value->schedule_id = $post["schedule"];
|
|
if ($value->door_access !== json_encode($post["doors"])) {
|
|
$value->door_access_old = $value->door_access;
|
|
}
|
|
$value->door_access = json_encode($post["doors"]);
|
|
$value->save();
|
|
}
|
|
$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" => $doors
|
|
];
|
|
}
|
|
}
|
|
|
|
}
|