116 lines
2.9 KiB
PHP
116 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace app\models;
|
|
|
|
use Yii;
|
|
|
|
/**
|
|
* This is the model class for table "auth_item".
|
|
*
|
|
* @property string $name
|
|
* @property int $type
|
|
* @property string $description
|
|
* @property string $rule_name
|
|
* @property resource $data
|
|
* @property int $created_at
|
|
* @property int $updated_at
|
|
*
|
|
* @property AuthItemChild[] $authItemChildren
|
|
* @property AuthItemChild[] $authItemChildren0
|
|
* @property AuthItem[] $children
|
|
* @property AuthItem[] $parents
|
|
*/
|
|
class AuthItem extends \yii\db\ActiveRecord {
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public static function tableName() {
|
|
return 'auth_item';
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function rules() {
|
|
return [
|
|
[['name', 'type'], 'required'],
|
|
[['type', 'created_at', 'updated_at'], 'integer'],
|
|
[['description', 'data'], 'string'],
|
|
[['name', 'rule_name'], 'string', 'max' => 64],
|
|
[['name'], 'unique'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function attributeLabels() {
|
|
return [
|
|
'name' => 'Tên quyền',
|
|
'type' => 'Type',
|
|
'description' => 'Ghi chú',
|
|
'rule_name' => 'Rule Name',
|
|
'data' => 'Data',
|
|
'created_at' => 'Ngày tạo',
|
|
'updated_at' => 'Updated At',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return \yii\db\ActiveQuery
|
|
*/
|
|
public function getAuthItemChildren() {
|
|
return $this->hasMany(AuthItemChild::className(), ['parent' => 'name']);
|
|
}
|
|
|
|
/**
|
|
* @return \yii\db\ActiveQuery
|
|
*/
|
|
public function getAuthItemChildren0() {
|
|
return $this->hasMany(AuthItemChild::className(), ['child' => 'name']);
|
|
}
|
|
|
|
/**
|
|
* @return \yii\db\ActiveQuery
|
|
*/
|
|
public function getChildren() {
|
|
return $this->hasMany(AuthItem::className(), ['name' => 'child'])->viaTable('auth_item_child', ['parent' => 'name']);
|
|
}
|
|
|
|
/**
|
|
* @return \yii\db\ActiveQuery
|
|
*/
|
|
public function getParents() {
|
|
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()->andWhere(['type' => 1])->all();
|
|
$re = [];
|
|
foreach ($ls as $key => $value) {
|
|
$re[$value->name] = Yii::t("app", $value->description);
|
|
}
|
|
return $re;
|
|
}
|
|
|
|
public function getChildList() {
|
|
$ls = AuthItemChild::find()->andWhere(['parent' => $this->name])->all();
|
|
$re = [];
|
|
foreach ($ls as $key => $value) {
|
|
$re[] = $value->child;
|
|
}
|
|
return $re;
|
|
}
|
|
|
|
}
|