HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbNavbar.php
Go to the documentation of this file.
1 <?php
10 Yii::import('booster.widgets.TbCollapse');
11 
18 class TbNavbar extends CWidget {
19 
20  const CONTAINER_PREFIX = 'yii_booster_collapse_';
21 
22  // Navbar types.
23  const TYPE_DEFAULT = 'default';
24  const TYPE_INVERSE = 'inverse';
25 
26  // Navbar fix locations.
27  const FIXED_TOP = 'top';
28  const FIXED_BOTTOM = 'bottom';
29 
35 
39  public $brand;
40 
44  public $brandUrl;
45 
49  public $brandOptions = array();
50 
55  public $items = array();
56 
64 
69  public $fluid = false;
70 
74  public $collapse = true;
75 
79  public $htmlOptions = array();
80 
86  public function init() {
87 
88  if ($this->brand !== false) {
89  if (!isset($this->brand)) {
90  $this->brand = CHtml::encode(Yii::app()->name);
91  }
92 
93  if (!isset($this->brandUrl)) {
94  $this->brandUrl = Yii::app()->homeUrl;
95  }
96 
97  $this->brandOptions['href'] = CHtml::normalizeUrl($this->brandUrl);
98 
99  if (isset($this->brandOptions['class'])) {
100  $this->brandOptions['class'] .= ' navbar-brand';
101  } else {
102  $this->brandOptions['class'] = 'navbar-brand';
103  }
104  }
105 
106  $classes = array('navbar');
107 
108  if (isset($this->type) && in_array($this->type, array(self::TYPE_DEFAULT, self::TYPE_INVERSE))) {
109  $classes[] = 'navbar-' . $this->type;
110  } else {
111  $classes[] = 'navbar-' . self::TYPE_DEFAULT;
112  }
113 
114  if ($this->fixed !== false && in_array($this->fixed, array(self::FIXED_TOP, self::FIXED_BOTTOM))) {
115  $classes[] = 'navbar-fixed-' . $this->fixed;
116  }
117 
118  if (!empty($classes)) {
119  $classes = implode(' ', $classes);
120  if (isset($this->htmlOptions['class'])) {
121  $this->htmlOptions['class'] .= ' ' . $classes;
122  } else {
123  $this->htmlOptions['class'] = $classes;
124  }
125  }
126  }
127 
133  public function run() {
134 
135  echo CHtml::openTag('nav', $this->htmlOptions);
136  echo '<div class="' . $this->getContainerCssClass() . '">';
137 
138  echo '<div class="navbar-header">';
139  if($this->collapse) {
140  $this->controller->widget('booster.widgets.TbButton', array(
141  'label' => '<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>',
142  'encodeLabel' => false,
143  'htmlOptions' => array(
144  'class' => 'navbar-toggle',
145  'data-toggle' => 'collapse',
146  'data-target' => '#'.self::CONTAINER_PREFIX.$this->id,
147  )
148  ));
149  }
150 
151  if ($this->brand !== false) {
152  if ($this->brandUrl !== false) {
153  echo CHtml::openTag('a', $this->brandOptions) . $this->brand . '</a>';
154  } else {
155  unset($this->brandOptions['href']); // spans cannot have a href attribute
156  echo CHtml::openTag('span', $this->brandOptions) . $this->brand . '</span>';
157  }
158  }
159  echo '</div>';
160 
161  echo '<div class="collapse navbar-collapse" id="'.self::CONTAINER_PREFIX.$this->id.'">';
162  foreach ($this->items as $item) {
163  if (is_string($item)) {
164  echo $item;
165  } else {
166  if (isset($item['class'])) {
167  $className = $item['class'];
168  unset($item['class']);
169 
170  $this->controller->widget($className, $item);
171  }
172  }
173  }
174  echo '</div></div></nav>';
175  }
176 
183  protected function getContainerCssClass() {
184 
185  return $this->fluid ? 'container-fluid' : 'container';
186  }
187 }