-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
executable file
·106 lines (96 loc) · 2.52 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
namespace common\models;
use common\behaviors\CacheInvalidateBehavior;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\caching\TagDependency;
/**
* This is the model class for table "{{%module}}".
*
* @property integer $id
* @property string $name
* @property string $title
* @property integer $status
* @property string $author
* @property integer $type
* @property string $desc
* @property string $config
* @property integer $created_at
* @property integer $updated_at
*/
class Module extends \yii\db\ActiveRecord
{
const STATUS_OPEN = 1;
const STATUS_CLOSE = 0;
const TYPE_CORE = 1;
const TYPE_PLUGIN = 2;
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%module}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'name'], 'required'],
[['status', 'type'], 'integer'],
[['type'], 'in', 'range' => [1,2]],
[['name'], 'string', 'max' => 50],
[['bootstrap'], 'string', 'max' => 128],
[['config'], 'string'],
['status', 'default', 'value' => 1],
[['id'], 'unique'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => '名称',
'bootstrap' => '初始化的应用',
'status' => '是否启用',
'config' => '配置',
'created_at' => '创建时间',
'updated_at' => '更新时间',
];
}
public function behaviors()
{
return [
TimestampBehavior::className(),
[
'class' => CacheInvalidateBehavior::className(),
'keys' => [
['modules', self::TYPE_CORE],
['modules', self::TYPE_PLUGIN],
]
]
];
}
public static function findOpenModules($type = null)
{
$modules = Yii::$app->cache->get(['modules', $type]);
if ($modules === false) {
$query = static::find();
$modules = $query->where(['status' => self::STATUS_OPEN])->andFilterWhere(['type' => $type])->all();
Yii::$app->cache->set(['modules', $type], $modules, 0);
}
return $modules;
}
public function getInstall()
{
return $this->isNewRecord ? false : true;
}
public function getOpen()
{
return $this->status == self::STATUS_OPEN;
}
}