DashboardPanel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 78
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A tableName() 0 4 1
A rules() 0 8 1
A attributeLabels() 0 13 1
A find() 0 4 1
A getDashboard() 0 4 1
A getPanel() 0 11 2
1
<?php
2
3
namespace cornernote\dashboard\models;
4
5
use cornernote\dashboard\ActiveRecord;
6
use cornernote\dashboard\models\query\DashboardPanelQuery;
7
use cornernote\dashboard\Panel;
8
use \Yii;
9
10
/**
11
 * This is the base-model class for table "dashboard_panel".
12
 *
13
 * @property string $id
14
 * @property string $dashboard_id
15
 * @property string $region
16
 * @property string $name
17
 * @property string $options
18
 * @property string $panel_class
19
 * @property integer $enabled
20
 * @property integer $sort
21
 * @property Dashboard $dashboard
22
 * @property Panel $panel
23
 */
24
class DashboardPanel extends ActiveRecord
25
{
26
    /**
27
     * @var Panel
28
     */
29
    private $_panel;
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public static function tableName()
35
    {
36
        return 'dashboard_panel';
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function rules()
43
    {
44
        return [
45
            [['dashboard_id', 'name', 'panel_class', 'enabled', 'sort'], 'required'],
46
            [['dashboard_id', 'sort', 'enabled'], 'integer'],
47
            [['name', 'panel_class', 'region'], 'string', 'max' => 255]
48
        ];
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function attributeLabels()
55
    {
56
        return [
57
            'id' => Yii::t('dashboard', 'ID'),
58
            'dashboard_id' => Yii::t('dashboard', 'Dashboard ID'),
59
            'region' => Yii::t('dashboard', 'Region'),
60
            'name' => Yii::t('dashboard', 'Name'),
61
            'options' => Yii::t('dashboard', 'Options'),
62
            'panel_class' => Yii::t('dashboard', 'Panel Class'),
63
            'enabled' => Yii::t('dashboard', 'Enabled'),
64
            'sort' => Yii::t('dashboard', 'Sort'),
65
        ];
66
    }
67
68
69
    /**
70
     * @inheritdoc
71
     * @return DashboardPanelQuery the active query used by this AR class.
72
     */
73
    public static function find()
74
    {
75
        return new DashboardPanelQuery(get_called_class());
76
    }
77
78
    /**
79
     * @return \yii\db\ActiveQuery
80
     */
81
    public function getDashboard()
82
    {
83
        return $this->hasOne(Dashboard::className(), ['id' => 'dashboard_id']);
84
    }
85
86
    /**
87
     * @return Panel
88
     */
89
    public function getPanel()
90
    {
91
        if (!$this->_panel) {
92
            $config = $this->options;
93
            $config['dashboardPanel'] = $this;
94
            $config['class'] = $this->panel_class;
95
            $config['id'] = 'dashboard-panel-' . $this->id;
96
            $this->_panel = Yii::createObject($config);
97
        }
98
        return $this->_panel;
99
    }
100
101
}
102