|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace cornernote\dashboard\models; |
|
4
|
|
|
|
|
5
|
|
|
use cornernote\dashboard\ActiveRecord; |
|
6
|
|
|
use cornernote\dashboard\Layout; |
|
7
|
|
|
use cornernote\dashboard\models\query\DashboardQuery; |
|
8
|
|
|
use \Yii; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* This is the base-model class for table "dashboard". |
|
12
|
|
|
* |
|
13
|
|
|
* @property string $id |
|
14
|
|
|
* @property string $name |
|
15
|
|
|
* @property string $layout_class |
|
16
|
|
|
* @property integer $enabled |
|
17
|
|
|
* @property integer $sort |
|
18
|
|
|
* @property string $options |
|
19
|
|
|
* @property DashboardPanel[] $dashboardPanels |
|
20
|
|
|
* @property Layout $layout |
|
21
|
|
|
*/ |
|
22
|
|
|
class Dashboard extends ActiveRecord |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var Layout |
|
26
|
|
|
*/ |
|
27
|
|
|
private $_layout; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @inheritdoc |
|
31
|
|
|
*/ |
|
32
|
|
|
public static function tableName() |
|
33
|
|
|
{ |
|
34
|
|
|
return 'dashboard'; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @inheritdoc |
|
39
|
|
|
*/ |
|
40
|
|
|
public function rules() |
|
41
|
|
|
{ |
|
42
|
|
|
return [ |
|
43
|
|
|
[['name', 'layout_class', 'enabled', 'sort'], 'required'], |
|
44
|
|
|
[['enabled', 'sort'], 'integer'], |
|
45
|
|
|
[['name', 'layout_class'], 'string', 'max' => 255] |
|
46
|
|
|
]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @inheritdoc |
|
51
|
|
|
*/ |
|
52
|
|
|
public function attributeLabels() |
|
53
|
|
|
{ |
|
54
|
|
|
return [ |
|
55
|
|
|
'id' => Yii::t('dashboard', 'ID'), |
|
56
|
|
|
'name' => Yii::t('dashboard', 'Name'), |
|
57
|
|
|
'layout_class' => Yii::t('dashboard', 'Layout Class'), |
|
58
|
|
|
'enabled' => Yii::t('dashboard', 'Enabled'), |
|
59
|
|
|
'sort' => Yii::t('dashboard', 'Sort'), |
|
60
|
|
|
'options' => Yii::t('dashboard', 'Options'), |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @inheritdoc |
|
67
|
|
|
* @return DashboardQuery the active query used by this AR class. |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function find() |
|
70
|
|
|
{ |
|
71
|
|
|
return new DashboardQuery(get_called_class()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return DashboardQuery |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getDashboardPanels() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->hasMany(DashboardPanel::className(), ['dashboard_id' => 'id']) |
|
80
|
|
|
->orderBy(['sort' => SORT_ASC]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return Layout |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getLayout() |
|
88
|
|
|
{ |
|
89
|
|
|
if (!$this->_layout) { |
|
90
|
|
|
$config = $this->options; |
|
91
|
|
|
$config['dashboard'] = $this; |
|
92
|
|
|
$config['class'] = $this->layout_class; |
|
93
|
|
|
$config['id'] = 'dashboard-' . $this->id; |
|
94
|
|
|
$this->_layout = Yii::createObject($config); |
|
95
|
|
|
} |
|
96
|
|
|
return $this->_layout; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param array $dashboardPanelSorts |
|
101
|
|
|
*/ |
|
102
|
|
|
public function sortPanels($dashboardPanelSorts) |
|
103
|
|
|
{ |
|
104
|
|
|
foreach ($dashboardPanelSorts as $region => $dashboardPanelSort) { |
|
105
|
|
|
foreach (explode(',', $dashboardPanelSort) as $k => $v) { |
|
106
|
|
|
$dashboardPanelId = str_replace('dashboard-panel-', '', $v); |
|
107
|
|
|
if ($dashboardPanelId) { |
|
108
|
|
|
$dashboardPanel = DashboardPanel::findOne($dashboardPanelId); |
|
109
|
|
|
if ($dashboardPanel) { |
|
110
|
|
|
$dashboardPanel->region = $region; |
|
111
|
|
|
$dashboardPanel->sort = $k; |
|
112
|
|
|
$dashboardPanel->save(false); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.