update phân quyền chi tiết
This commit is contained in:
@@ -47,12 +47,12 @@ class AuthItem extends \yii\db\ActiveRecord {
|
||||
*/
|
||||
public function attributeLabels() {
|
||||
return [
|
||||
'name' => 'Name',
|
||||
'name' => 'Tên quyền',
|
||||
'type' => 'Type',
|
||||
'description' => 'Description',
|
||||
'description' => 'Ghi chú',
|
||||
'rule_name' => 'Rule Name',
|
||||
'data' => 'Data',
|
||||
'created_at' => 'Created At',
|
||||
'created_at' => 'Ngày tạo',
|
||||
'updated_at' => 'Updated At',
|
||||
];
|
||||
}
|
||||
@@ -85,8 +85,17 @@ class AuthItem extends \yii\db\ActiveRecord {
|
||||
return $this->hasMany(AuthItem::className(), ['name' => 'parent'])->viaTable('auth_item_child', ['child' => 'name']);
|
||||
}
|
||||
|
||||
public static $roleArray = [
|
||||
"department" => "Phòng ban",
|
||||
"staff" => "Nhân viên",
|
||||
"area" => "Khu vực",
|
||||
"device" => "Thiết bị",
|
||||
"schedule" => "Kiểm soát truy cập",
|
||||
"logs" => "Báo cáo"
|
||||
];
|
||||
|
||||
public static function roleArray() {
|
||||
$ls = self::find()->all();
|
||||
$ls = self::find()->andWhere(['type' => 1])->all();
|
||||
$re = [];
|
||||
foreach ($ls as $key => $value) {
|
||||
$re[$value->name] = Yii::t("app", $value->description);
|
||||
@@ -94,4 +103,13 @@ class AuthItem extends \yii\db\ActiveRecord {
|
||||
return $re;
|
||||
}
|
||||
|
||||
public function getChildList() {
|
||||
$ls = AuthItemChild::find()->andWhere(['parent' => $this->name])->all();
|
||||
$re = [];
|
||||
foreach ($ls as $key => $value) {
|
||||
$re[] = $value->child;
|
||||
}
|
||||
return $re;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
66
models/AuthItemChild.php
Normal file
66
models/AuthItemChild.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "auth_item_child".
|
||||
*
|
||||
* @property string $parent
|
||||
* @property string $child
|
||||
*
|
||||
* @property AuthItem $parent0
|
||||
* @property AuthItem $child0
|
||||
*/
|
||||
class AuthItemChild extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'auth_item_child';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['parent', 'child'], 'required'],
|
||||
[['parent', 'child'], 'string', 'max' => 64],
|
||||
[['parent', 'child'], 'unique', 'targetAttribute' => ['parent', 'child']],
|
||||
[['parent'], 'exist', 'skipOnError' => true, 'targetClass' => AuthItem::className(), 'targetAttribute' => ['parent' => 'name']],
|
||||
[['child'], 'exist', 'skipOnError' => true, 'targetClass' => AuthItem::className(), 'targetAttribute' => ['child' => 'name']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'parent' => 'Parent',
|
||||
'child' => 'Child',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getParent0()
|
||||
{
|
||||
return $this->hasOne(AuthItem::className(), ['name' => 'parent']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getChild0()
|
||||
{
|
||||
return $this->hasOne(AuthItem::className(), ['name' => 'child']);
|
||||
}
|
||||
}
|
||||
74
models/AuthItemSearch.php
Normal file
74
models/AuthItemSearch.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use app\models\AuthItem;
|
||||
|
||||
/**
|
||||
* AuthItemSearch represents the model behind the search form of `app\models\AuthItem`.
|
||||
*/
|
||||
class AuthItemSearch extends AuthItem
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name', 'description', 'rule_name', 'data'], 'safe'],
|
||||
[['type', 'created_at', 'updated_at'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 = AuthItem::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([
|
||||
'type' => $this->type,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'name', $this->name])
|
||||
->andFilterWhere(['like', 'description', $this->description])
|
||||
->andFilterWhere(['like', 'rule_name', $this->rule_name])
|
||||
->andFilterWhere(['like', 'data', $this->data]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user