1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) CJT TERABYTE INC |
5
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @link: https://github.com/cjtterabytesoft/sidebar |
9
|
|
|
* @author: Wilmer Arámbula <[email protected]> |
10
|
|
|
* @copyright: (c) CJT TERABYTE INC |
11
|
|
|
* @widget: [Sidebar] |
12
|
|
|
* @since: 1.0 |
13
|
|
|
* @yii: 3.0 |
14
|
|
|
**/ |
15
|
|
|
|
16
|
|
|
namespace cjtterabytesoft\widgets; |
17
|
|
|
|
18
|
|
|
use yii\helpers\ArrayHelper; |
19
|
|
|
use yii\helpers\Html; |
20
|
|
|
use yii\helpers\Url; |
21
|
|
|
use yii\widgets\Menu; |
22
|
|
|
|
23
|
|
|
class Sidebar extends Menu |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $linkTemplate = '<a href="{url}" {linkOptions}>\n{icon}\n{label}\n{right-icon}\n{badge}</a>'; |
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
public $labelTemplate = '{icon}\n{label}\n{badge}'; |
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
public $submenuTemplate = "\n<ul class=\"dropdown-menu\">\n{items}\n</ul>\n"; |
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
public $badgeTag = 'small'; |
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
public $badgeClass = 'badge pull-right'; |
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
public $badgeBgClass = 'bg-green'; |
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
public $parentRightIcon = '<span class="arrow"><i class="ti-angle-right"></i></span>'; |
53
|
|
|
/** |
54
|
|
|
* @inheritdoc |
55
|
|
|
*/ |
56
|
|
|
protected function renderItem($item) |
57
|
|
|
{ |
58
|
|
|
$item['badgeOptions'] = isset($item['badgeOptions']) ? $item['badgeOptions'] : []; |
59
|
|
|
if (!ArrayHelper::getValue($item, 'badgeOptions.class')) { |
60
|
|
|
$bg = isset($item['badgeBgClass']) ? $item['badgeBgClass'] : $this->badgeBgClass; |
61
|
|
|
$item['badgeOptions']['class'] = $this->badgeClass . ' ' . $bg; |
62
|
|
|
} |
63
|
|
|
if (isset($item['items']) && !isset($item['right-icon'])) { |
64
|
|
|
$item['right-icon'] = $this->parentRightIcon; |
65
|
|
|
} |
66
|
|
|
$template = ArrayHelper::getValue( |
67
|
|
|
$item, |
68
|
|
|
'template', |
69
|
|
|
isset($item['url']) ? $this->linkTemplate : $this->labelTemplate |
70
|
|
|
); |
71
|
|
|
return strtr($template, [ |
72
|
|
|
'{badge}' => isset($item['badge']) ? Html::tag('small', $item['badge'], $item['badgeOptions']) : '', |
73
|
|
|
'{icon}' => isset($item['icon']) ? $item['icon'] : '', |
74
|
|
|
'{right-icon}' => isset($item['right-icon']) ? $item['right-icon'] : '', |
75
|
|
|
'{url}' => isset($item['url']) ? Url::to($item['url']) : '', |
76
|
|
|
'{label}' => $item['label'], |
77
|
|
|
'{linkOptions}' => isset($item['linkOptions']) ? Html::renderTagAttributes($item['linkOptions']) : '', |
78
|
|
|
]); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|