Completed
Push — master ( 3c8880...e2c218 )
by Dmitry
06:42 queued 02:46
created

IndexLayoutSwitcher::isOrientation()   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
rs 10
ccs 0
cts 4
cp 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * HiPanel core package
5
 *
6
 * @link      https://hipanel.com/
7
 * @package   hipanel-core
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\widgets;
13
14
use hipanel\base\OrientationStorage;
15
use Yii;
16
use yii\base\Widget;
17
use yii\bootstrap\ButtonGroup;
18
use yii\helpers\Html;
19
20
class IndexLayoutSwitcher extends Widget
21
{
22
    public function run()
23
    {
24
        return ButtonGroup::widget([
25
            'encodeLabels' => false,
26
            'buttons' => [
27
                Html::a(
28
                    '<i class="fa fa-pause" aria-hidden="true"></i>',
29
                    ['set-orientation', 'orientation' => OrientationStorage::ORIENTATION_HORIZONTAL, 'route' => Yii::$app->controller->getRoute()],
30
                    ['class' => 'btn btn-default btn-sm ' . ($this->isOrientation(OrientationStorage::ORIENTATION_HORIZONTAL) ? 'active' : '')]),
31
                Html::a(
32
                    '<i class="fa fa-pause fa-rotate-90" aria-hidden="true"></i>',
33
                    ['set-orientation', 'orientation' => OrientationStorage::ORIENTATION_VERTICAL, 'route' => Yii::$app->controller->getRoute()],
34
                    ['class' => 'btn btn-default btn-sm ' . ($this->isOrientation(OrientationStorage::ORIENTATION_VERTICAL) ? 'active' : '')]),
35
            ],
36
        ]);
37
    }
38
39
    /**
40
     * @param $orientation
41
     * @return bool
42
     */
43
    private function isOrientation($orientation)
44
    {
45
        return Yii::$app->get('orientationStorage')->get(Yii::$app->controller->route) === $orientation;
46
    }
47
}
48