Completed
Push — master ( 92c94a...03ed10 )
by Dmitry
26:12 queued 11:12
created

IndexLayoutSwitcher::getClassActive()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * HiPanel core package.
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\widgets;
12
13
use hipanel\helpers\Url;
14
use hipanel\models\IndexPageUiOptions;
15
use yii\base\Widget;
16
use yii\bootstrap\ButtonGroup;
17
use yii\helpers\Html;
18
19
class IndexLayoutSwitcher extends Widget
20
{
21
    /**
22
     * @var IndexPageUiOptions
23
     */
24
    public $uiModel;
25
26
    public function run()
27
    {
28
        return ButtonGroup::widget([
29
            'encodeLabels' => false,
30
            'buttons' => [
31
                Html::a(
32
                    '<i class="fa fa-pause" aria-hidden="true"></i>',
33
                    Url::current(['orientation' => IndexPageUiOptions::ORIENTATION_HORIZONTAL]),
34
                    ['class' => 'btn btn-default btn-sm ' .
35
                            $this->getClassActive(IndexPageUiOptions::ORIENTATION_HORIZONTAL)
36
                    ]),
37
                Html::a(
38
                    '<i class="fa fa-pause fa-rotate-90" aria-hidden="true"></i>',
39
                    Url::current(['orientation' => IndexPageUiOptions::ORIENTATION_VERTICAL]),
40
                    ['class' => 'btn btn-default btn-sm ' .
41
                            $this->getClassActive(IndexPageUiOptions::ORIENTATION_VERTICAL)
42
                    ]),
43
            ],
44
        ]);
45
    }
46
47
    /**
48
     * @param string $orientation
49
     * @return string
50
     */
51
    private function getClassActive(string $orientation): string
52
    {
53
        return $this->isOriented($orientation) ? 'active' : '';
54
    }
55
56
    /**
57
     * @param $orientation
58
     * @return bool
59
     */
60
    private function isOriented(string $orientation): bool
61
    {
62
        return $this->uiModel->orientation === $orientation;
63
    }
64
}
65