Panel::load()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace cornernote\dashboard;
4
5
use cornernote\dashboard\models\DashboardPanel;
6
use Yii;
7
use yii\base\Model;
8
use yii\bootstrap\ActiveForm;
9
10
/**
11
 * Panel
12
 * @package cornernote\dashboard
13
 */
14
class Panel extends Model
15
{
16
    /**
17
     * @var string
18
     */
19
    public $id;
20
21
    /**
22
     * @var string
23
     */
24
    public $viewPath;
25
26
    /**
27
     * @var DashboardPanel
28
     */
29
    public $dashboardPanel;
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function load($data, $formName = null)
35
    {
36
        $this->dashboardPanel->load($data);
37
        return parent::load($data, $formName);
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function afterValidate()
44
    {
45
        if (!$this->dashboardPanel->validate()) {
46
            $this->addError(null);
47
        }
48
        parent::afterValidate();
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function getOptions()
55
    {
56
        $attributes = [];
57
        foreach($this->safeAttributes() as $attribute){
58
            $attributes[$attribute] = $this->$attribute;
59
        }
60
        return $attributes;
61
    }
62
63
    /**
64
     * @param string $view
65
     * @param array $params
66
     * @return string
67
     */
68
    public function render($view, $params = [])
69
    {
70
        $params['panel'] = $this;
71
        return \Yii::$app->view->render($this->viewPath . '/' . $view, $params);
72
    }
73
74
}
75