Completed
Push — master ( b99abb...0ebb43 )
by Andrii
02:11
created

Panel::setViewPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace hiqdev\thememanager\debug;
4
5
use Yii;
6
use yii\base\ViewContextInterface;
7
use yii\helpers\ArrayHelper;
8
9
class Panel extends \yii\debug\Panel implements ViewContextInterface
10
{
11
    use \hiqdev\thememanager\GetManagerTrait;
12
13
    protected $_viewPath;
14
15
    public function setViewPath($value)
16
    {
17
        $this->_viewPath = $value;
18
    }
19
20
    public function getViewPath()
21
    {
22
        if ($this->_viewPath === null) {
23
            $this->_viewPath = dirname(__DIR__) . '/views/debug';
24
        }
25
        return $this->_viewPath;
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function getName()
32
    {
33
        return 'Themes';
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function getSummary()
40
    {
41
        return Yii::$app->view->render('summary', ['panel' => $this], $this);
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function getDetail()
48
    {
49
        return Yii::$app->view->render('detail', ['panel' => $this], $this);
50
    }
51
52
    public function getThemes()
53
    {
54
        return isset($this->data['themes']) ? $this->data['themes'] : [];
55
    }
56
57
    public function getCount()
58
    {
59
        return count($this->getThemes());
60
    }
61
62
    public function getCurrent()
63
    {
64
        return isset($this->data['current']) ? $this->data['current'] : '';
65
    }
66
67
    public function getDefault()
68
    {
69
        return isset($this->data['default']) ? $this->data['default'] : '';
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75
    public function save()
76
    {
77
        $raw = $this->getManager()->getItems();
78
        $themes = ArrayHelper::toArray($raw);
79
        foreach ($raw as $name => $theme) {
80
            $themes[$name]['class'] = get_class($theme);
81
        }
82
        
83
        return [
84
            'themes' => $themes,
85
            'current' => $this->getManager()->getTheme()->name,
86
            'default' => $this->getManager()->getDefaultTheme(),
87
        ];
88
    }
89
}
90