update Area + Device

This commit is contained in:
2020-10-08 17:12:19 +07:00
parent 2d15fc1c14
commit 0273aa2179
31 changed files with 1475 additions and 557 deletions

54
models/Area.php Normal file
View File

@@ -0,0 +1,54 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "area".
*
* @property int $id
* @property int $code
* @property int $pid
* @property string $name
* @property string $description
* @property int $created_at
* @property int $modified_at
*/
class Area extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'area';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['code', 'name'], 'required'],
[['code', 'pid', 'created_at', 'modified_at'], 'integer'],
[['description'], 'string'],
[['name'], 'string', 'max' => 100],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'code' => 'Mã khu vực',
'pid' => 'Khu vực cha',
'name' => 'Tên khu vực',
'description' => 'Chú thích',
'created_at' => 'Thời gian tạo',
'modified_at' => 'Thời gian sửa',
];
}
}

74
models/AreaSearch.php Normal file
View File

@@ -0,0 +1,74 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Area;
/**
* AreaSearch represents the model behind the search form of `app\models\Area`.
*/
class AreaSearch extends Area
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'code', 'pid', 'created_at', 'modified_at'], 'integer'],
[['name', 'description'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Area::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'code' => $this->code,
'pid' => $this->pid,
'created_at' => $this->created_at,
'modified_at' => $this->modified_at,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'description', $this->description]);
return $dataProvider;
}
}

View File

@@ -91,15 +91,10 @@ class Department extends \yii\db\ActiveRecord {
self::deleteDepartment($value->id);
}
$model->delete();
self::insertSystemLogs(["action" => "delete", "description" => "Xóa phòng ban: " . $model->name]);
common::insertSystemLogs(["action" => "delete", "description" => "Xóa phòng ban: " . $model->name, "type" => "department"]);
}
}
public static function insertSystemLogs($data) {
$model = new LogsDepartment();
return $model->create($data);
}
public function checkStatusImport($data) {
if ($this->findOne(["code" => $data["A"]]))
return ["status" => false, "description" => "Mã phòng ban đã tồn tại"];

61
models/Device.php Normal file
View File

@@ -0,0 +1,61 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "device".
*
* @property int $id
* @property string $name
* @property string $serial
* @property string $ip_address
* @property int $status
* @property int $type
* @property int $area_id
* @property int $created_at
* @property int $modified_at
*/
class Device extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'device';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name', 'ip_address', 'status', 'type', 'area_id'], 'required'],
[['status', 'type', 'area_id', 'created_at', 'modified_at'], 'integer'],
[['name'], 'string', 'max' => 100],
[['serial'], 'string', 'max' => 50],
[['ip_address'], 'string', 'max' => 20],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
'serial' => 'Serial',
'ip_address' => 'Ip Address',
'status' => 'Status',
'type' => 'Type',
'area_id' => 'Area ID',
'created_at' => 'Created At',
'modified_at' => 'Modified At',
];
}
}

76
models/DeviceSearch.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Device;
/**
* DeviceSearch represents the model behind the search form of `app\models\Device`.
*/
class DeviceSearch extends Device
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'status', 'type', 'area_id', 'created_at', 'modified_at'], 'integer'],
[['name', 'serial', 'ip_address'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Device::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'status' => $this->status,
'type' => $this->type,
'area_id' => $this->area_id,
'created_at' => $this->created_at,
'modified_at' => $this->modified_at,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'serial', $this->serial])
->andFilterWhere(['like', 'ip_address', $this->ip_address]);
return $dataProvider;
}
}

View File

@@ -5,21 +5,22 @@ namespace app\models;
use Yii;
/**
* This is the model class for table "logs_department".
* This is the model class for table "system_logs".
*
* @property int $id
* @property int $user_id
* @property int $time
* @property string $action
* @property string $description
* @property string $type
*/
class LogsDepartment extends \yii\db\ActiveRecord {
class SystemLogs extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'logs_department';
return 'system_logs';
}
/**
@@ -27,10 +28,11 @@ class LogsDepartment extends \yii\db\ActiveRecord {
*/
public function rules() {
return [
[['user_id', 'time', 'action', 'description'], 'required'],
[['user_id', 'time', 'action', 'description', 'type'], 'required'],
[['user_id', 'time'], 'integer'],
[['description'], 'string'],
[['action'], 'string', 'max' => 10],
[['type'], 'string', 'max' => 100],
];
}
@@ -44,6 +46,7 @@ class LogsDepartment extends \yii\db\ActiveRecord {
'time' => 'Time',
'action' => 'Action',
'description' => 'Description',
'type' => 'Type',
];
}
@@ -52,7 +55,8 @@ class LogsDepartment extends \yii\db\ActiveRecord {
'user_id' => Yii::$app->user->id,
'time' => time(),
'action' => $data['action'],
'description' => $data['description']
'description' => $data['description'],
'type' => $data['type']
], '');
if ($r) {
try {

View File

@@ -171,4 +171,16 @@ class common extends \yii\db\ActiveRecord {
return $visible;
}
public static function SaveViaTempFile($objWriter) {
$filePath = rand(0, getrandmax()) . rand(0, getrandmax()) . ".tmp";
$objWriter->save($filePath);
readfile($filePath);
unlink($filePath);
}
public static function insertSystemLogs($data) {
$model = new SystemLogs();
return $model->create($data);
}
}