update Area + Device
This commit is contained in:
92
controllers/AreaController.php
Normal file
92
controllers/AreaController.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use Yii;
|
||||
use app\models\Area;
|
||||
use app\models\AreaSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* AreaController implements the CRUD actions for Area model.
|
||||
*/
|
||||
class AreaController 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 = 'Khu vực';
|
||||
$searchModel = new AreaSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionView($id) {
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionCreate() {
|
||||
$model = new Area();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionUpdate($id) {
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionDelete($id) {
|
||||
$this->findModel($id)->delete();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
protected function findModel($id) {
|
||||
if (($model = Area::findOne($id)) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace app\controllers;
|
||||
use Yii;
|
||||
use app\models\Department;
|
||||
use app\models\DepartmentSearch;
|
||||
use app\models\LogsDepartment;
|
||||
use app\models\SystemLogs;
|
||||
use app\models\common;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
@@ -60,7 +60,7 @@ class DepartmentController extends Controller {
|
||||
return ["status" => false, "type" => "code"];
|
||||
|
||||
if ($model->create($data)) {
|
||||
Department::insertSystemLogs(["action" => "insert", "description" => "Thêm mới phòng ban: " . $data["Name"]]);
|
||||
common::insertSystemLogs(["action" => "insert", "description" => "Thêm mới phòng ban: " . $data["Name"], "type" => Yii::$app->controller->id]);
|
||||
return ["status" => true];
|
||||
} else
|
||||
return ["status" => false, "type" => "error"];
|
||||
@@ -91,7 +91,7 @@ class DepartmentController extends Controller {
|
||||
$model->modified_at = time();
|
||||
if ($model->save()) {
|
||||
Department::updateAll(["pid" => $data["Code"]], ["pid" => $oldCode]);
|
||||
Department::insertSystemLogs(["action" => "update", "description" => "Chỉnh sửa phòng ban: " . $data["Name"]]);
|
||||
common::insertSystemLogs(["action" => "update", "description" => "Chỉnh sửa phòng ban: " . $data["Name"], "type" => Yii::$app->controller->id]);
|
||||
return ["status" => true];
|
||||
} else
|
||||
return ["status" => false, "type" => "error"];
|
||||
@@ -181,7 +181,7 @@ class DepartmentController extends Controller {
|
||||
header('Content-type: application/vnd.ms-excel');
|
||||
header('Content-Disposition: attachment; filename="department_' . date("YmdHis") . '.xlsx"');
|
||||
header('Cache-Control: max-age=0');
|
||||
$objWriter->save('php://output');
|
||||
common::SaveViaTempFile($objWriter);
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ class DepartmentController extends Controller {
|
||||
}
|
||||
$model = new Department();
|
||||
$model->multiCreate($datas);
|
||||
Department::insertSystemLogs(["action" => "import", "description" => "Nhập dữ liệu: " . count($post) . " phòng ban mới"]);
|
||||
common::insertSystemLogs(["action" => "import", "description" => "Nhập dữ liệu: " . count($post) . " phòng ban mới", "type" => Yii::$app->controller->id]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -226,11 +226,34 @@ class DepartmentController extends Controller {
|
||||
return [
|
||||
"title" => Html::tag("i", "", ["class" => "fa fa-file"]) . " Ghi nhận hệ thống",
|
||||
"form" => $this->renderPartial("logs", [
|
||||
"logs" => LogsDepartment::find()->orderBy(['time' => SORT_DESC])->limit(30)->all(),
|
||||
"logs" => SystemLogs::find()->andWhere(["type" => Yii::$app->controller->id])->orderBy(['time' => SORT_DESC])->limit(30)->all(),
|
||||
"userArray" => \app\models\User::userArray()
|
||||
])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function actionTree() {
|
||||
if (Yii::$app->request->isAjax) {
|
||||
Yii::$app->response->format = "json";
|
||||
return [
|
||||
"title" => Html::tag("i", "", ["class" => "fa fa-sitemap"]) . " Cây thư mục",
|
||||
"form" => $this->renderPartial("tree", [
|
||||
"root" => Department::findOne(1)
|
||||
])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function actionTest() {
|
||||
$test = file_get_contents("http://192.168.2.119:2001/TestConnection", false, stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST",
|
||||
'content' => json_encode(["DeviceIP" => "192.168.1.201"])
|
||||
]
|
||||
]));
|
||||
return var_dump($test);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
92
controllers/DeviceController.php
Normal file
92
controllers/DeviceController.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use Yii;
|
||||
use app\models\Device;
|
||||
use app\models\DeviceSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* DeviceController implements the CRUD actions for Device model.
|
||||
*/
|
||||
class DeviceController 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 = 'Thiết bị';
|
||||
$searchModel = new DeviceSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionView($id) {
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionCreate() {
|
||||
$model = new Device();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionUpdate($id) {
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionDelete($id) {
|
||||
$this->findModel($id)->delete();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
protected function findModel($id) {
|
||||
if (($model = Device::findOne($id)) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user