update gán lịch trình cho nhân viên
This commit is contained in:
91
controllers/AssignController.php
Normal file
91
controllers/AssignController.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?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 yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
|
||||
/**
|
||||
* DeviceController implements the CRUD actions for Device model.
|
||||
*/
|
||||
class AssignController extends Controller {
|
||||
|
||||
public function init() {
|
||||
parent::init();
|
||||
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 = '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)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user