1: <?php
2: 3: 4: 5: 6: 7: 8:
9:
10: Yii::import('bootstrap.helpers.TbHtml');
11:
12: 13: 14: 15:
16: class TbNavbar extends CWidget
17: {
18: 19: 20:
21: public $color;
22: 23: 24:
25: public $brandLabel;
26: 27: 28:
29: public $brandUrl;
30: 31: 32:
33: public $brandOptions = array();
34: 35: 36:
37: public $display = TbHtml::NAVBAR_DISPLAY_FIXEDTOP;
38: 39: 40:
41: public $fluid = false;
42: 43: 44:
45: public $collapse = false;
46: 47: 48:
49: public $collapseOptions = array();
50: 51: 52:
53: public $items = array();
54: 55: 56:
57: public $htmlOptions = array();
58:
59: 60: 61:
62: public function init()
63: {
64: if ($this->brandLabel !== false) {
65: if (!isset($this->brandLabel)) {
66: $this->brandLabel = CHtml::encode(Yii::app()->name);
67: }
68:
69: if (!isset($this->brandUrl)) {
70: $this->brandUrl = Yii::app()->homeUrl;
71: }
72: }
73: if (isset($this->color)) {
74: TbArray::defaultValue('color', $this->color, $this->htmlOptions);
75: }
76: if (isset($this->display) && $this->display !== TbHtml::NAVBAR_DISPLAY_NONE) {
77: TbArray::defaultValue('display', $this->display, $this->htmlOptions);
78: }
79: }
80:
81: 82: 83:
84: public function run()
85: {
86: $brand = $this->brandLabel !== false
87: ? TbHtml::navbarBrandLink($this->brandLabel, $this->brandUrl, $this->brandOptions)
88: : '';
89: ob_start();
90: foreach ($this->items as $item) {
91: if (is_string($item)) {
92: echo $item;
93: } else {
94: $widgetClassName = TbArray::popValue('class', $item);
95: if ($widgetClassName !== null) {
96: $this->controller->widget($widgetClassName, $item);
97: }
98: }
99: }
100: $items = ob_get_clean();
101: ob_start();
102: if ($this->collapse !== false) {
103: TbHtml::addCssClass('nav-collapse', $this->collapseOptions);
104: ob_start();
105:
106: $collapseWidget = $this->controller->widget(
107: 'bootstrap.widgets.TbCollapse',
108: array(
109: 'toggle' => false,
110: 'content' => $items,
111: 'htmlOptions' => $this->collapseOptions,
112: )
113: );
114: $collapseContent = ob_get_clean();
115: echo TbHtml::navbarCollapseLink('#' . $collapseWidget->getId());
116: echo $brand . $collapseContent;
117:
118: } else {
119: echo $brand . $items;
120: }
121: $containerContent = ob_get_clean();
122: $containerOptions = TbArray::popValue('containerOptions', $this->htmlOptions, array());
123: TbHtml::addCssClass($this->fluid ? 'container-fluid' : 'container', $containerOptions);
124: ob_start();
125: echo TbHtml::openTag('div', $containerOptions);
126: echo $containerContent;
127: echo '</div>';
128: $content = ob_get_clean();
129: echo TbHtml::navbar($content, $this->htmlOptions);
130: }
131: }