Passed
Push — master ( a3074c...38e910 )
by Alexey
02:36
created

Base::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace backend\widgets\chart\morris;
4
5
use backend\widgets\chart\morris\assets\MorrisAsset;
6
use yii\base\Widget;
7
use yii\helpers\ArrayHelper;
8
use yii\helpers\Html;
9
10
/**
11
 * Class Base
12
 *
13
 * @package backend\widgets\chart\morris
14
 */
15
abstract class Base extends Widget
16
{
17
    /** @var bool */
18
    public $status = true;
19
    /** @var array */
20
    public $containerOptions = [];
21
    /** @var array */
22
    public $clientOptions = [];
23
24
    /**
25
     * @inheritDoc
26
     */
27
    public function init()
28
    {
29
        parent::init();
30
        if ($this->status === true) {
31
            $this->registerAsset();
32
        }
33
        $this->id = $this->id ?: $this->getId();
34
        $containerOptions = [
35
            'id' => $this->id,
36
            'style' => 'position:relative; height:300px; width:auto;'
37
        ];
38
        $this->containerOptions = ArrayHelper::merge($containerOptions, $this->containerOptions);
39
    }
40
41
    /**
42
     * Run
43
     *
44
     * @return string
45
     */
46
    public function run()
47
    {
48
        return Html::tag('div', '', $this->containerOptions);
49
    }
50
51
    /**
52
     * Client Options
53
     *
54
     * @return array
55
     */
56
    public function getClientOptions()
57
    {
58
        return [
59
            'element' => $this->id,
60
            'resize' => true,
61
            'hideHover' => 'auto',
62
            'data' => [],
63
        ];
64
    }
65
66
    /**
67
     * Register Asset
68
     */
69
    public function registerAsset()
70
    {
71
        $view = $this->getView();
72
        MorrisAsset::register($view);
73
    }
74
}
75