-
Notifications
You must be signed in to change notification settings - Fork 33
/
EBootstrapSidebar.php
113 lines (99 loc) · 3.1 KB
/
EBootstrapSidebar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
Yii::import('zii.widgets.CMenu');
/**
* Render a sidebar
*
* @author Tim Helfensdörfer <tim@visualappeal.de>
* @version 0.3.0
* @package bootstrap.widgets
*/
class EBootstrapSidebar extends CMenu {
/**
* Init the widget
*/
public function init()
{
echo EBootstrap::openTag('div', array('class' => 'well sidebar-nav'));
EBootstrap::mergeClass($this->htmlOptions, array('nav', 'nav-pills', 'nav-stacked'));
parent::init();
}
public function run() {
parent::run();
echo EBootstrap::closeTag('div');
}
/**
* Recursively renders the menu items.
*
* @param array $items the menu items to be rendered recursively
* @param bool $header Helper variable to identify the header elements
*/
protected function renderMenuRecursive($items, $header = true) {
$count=0;
$n=count($items);
foreach($items as $item) {
if (isset($item['access']) and (!empty($item['access'])))
$prove = true;
else
$prove = false;
if (($prove and Yii::app()->user->checkAccess($item['access'])) or (!$prove)) {
$count++;
$options=isset($item['itemOptions']) ? $item['itemOptions'] : array();
$class=array();
if($item['active'] && $this->activeCssClass!='')
$class[]=$this->activeCssClass;
if($count===1 && $this->firstItemCssClass!==null)
$class[]=$this->firstItemCssClass;
if($count===$n && $this->lastItemCssClass!==null)
$class[]=$this->lastItemCssClass;
if($this->itemCssClass!==null)
$class[]=$this->itemCssClass;
if (($header and (isset($item['items']))) or (isset($item['header']) and ($item['header'] == true)))
$class[]='nav-header';
if($class!==array()) {
if(empty($options['class']))
$options['class']=implode(' ',$class);
else
$options['class'].=' '.implode(' ',$class);
}
echo EBootstrap::openTag('li', $options);
$menu=$this->renderMenuItem($item);
if(isset($this->itemTemplate) || isset($item['template'])) {
$template=isset($item['template']) ? $item['template'] : $this->itemTemplate;
echo strtr($template,array('{menu}'=>$menu));
}
else
echo $menu;
echo EBootstrap::closeTag('li');
if(isset($item['items']) && count($item['items'])) {
$this->renderMenuRecursive($item['items'], false);
}
echo "\n";
}
}
}
/**
* Renders the content of a menu item.
*
* You can pass an 'icon' as item option as well as a bolean 'iconWhite'
*/
protected function renderMenuItem($item)
{
if (isset($item['icon']) and !empty($item['icon'])) {
$icon = '<i class="icon-'.$item['icon'];
if (isset($item['iconWhite']) and ($item['iconWhite'] == true))
$icon .= ' icon-white';
$icon .= '"></i> ';
}
else {
$icon = '';
}
if(isset($item['url'])) {
$label=$this->linkLabelWrapper===null ? $icon.$item['label'] : '<'.$this->linkLabelWrapper.'>'.$icon.$item['label'].'</'.$this->linkLabelWrapper.'>';
return EBootstrap::link($label,$item['url'],isset($item['linkOptions']) ? $item['linkOptions'] : array());
}
else {
return EBootstrap::tag('span',isset($item['linkOptions']) ? $item['linkOptions'] : array(), $icon.$item['label']);
}
}
}
?>