/** * Renders the alert * @return string the rendering result */ public function renderAlert() { $user = \Yii::app()->user; if (count($user->getFlashes(false)) == 0) { return; } $alerts = array(); foreach ($this->config as $style => $config) { if ($user->hasFlash($style)) { $options = ArrayHelper::getValue($config, 'htmlOptions', array()); Html::addCssClass($options, $style); $close = ArrayHelper::getValue($config, 'close', '×'); $alerts[] = \foundation\helpers\Alert::alert($user->getFlash($style), $options, $close); } } $this->registerEvents("#{$this->htmlOptions['id']} > .alert-box", $this->events); return \CHtml::tag('div', $this->htmlOptions, implode("\n", $alerts)); }
/** * Renders dropdown items * @return string * @throws InvalidConfigException */ protected function renderItems() { $lines = array(); if ($this->type === Enum::DROPDOWN_CONTENT) { $lines[] = $this->dropdownContent; } if ($this->type === Enum::DROPDOWN_LIST) { foreach ($this->items as $item) { if (is_string($item)) { $lines[] = $item; continue; } if (!isset($item['label'])) { throw new InvalidConfigException("The 'label' option is required."); } $label = $this->encodeLabels ? \CHtml::encode($item['label']) : $item['label']; $options = ArrayHelper::getValue($item, 'options', array()); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); $linkOptions['tabindex'] = '-1'; $content = \CHtml::link($label, ArrayHelper::getValue($item, 'url', '#'), $linkOptions); $lines[] = \CHtml::tag('li', $options, $content); } } return \CHtml::tag('ul', $this->htmlOptions, implode("\n", $lines)); }
/** * Renders menu items. It differs from [[Dropdown]] widget as it is factorial to render multi-level dropdown menus. * @param array $items the items to render * @param bool $encodeLabels whether to encode link labels or not * @return string the resulting dropdown element. * @throws \foundation\exception\InvalidConfigException */ public static function dropdown($items, $encodeLabels = true) { $li = array(); foreach ($items as $item) { if (is_string($item)) { $li[] = $item; continue; } if (!isset($item['label'])) { throw new InvalidConfigException("The 'label' option is required."); } $label = $encodeLabels ? \CHtml::encode($item['label']) : $item['label']; $options = ArrayHelper::getValue($item, 'options', array()); $items = ArrayHelper::getValue($item, 'items'); $url = \CHtml::normalizeUrl(ArrayHelper::getValue($item, 'url', '#')); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); if (ArrayHelper::getValue($item, 'active')) { ArrayHelper::addValue('class', 'active', $options); } if ($items !== null) { ArrayHelper::addValue('class', 'has-dropdown', $options); if (is_array($items)) { $items = static::dropdown($items, $encodeLabels); } } $li[] = \CHtml::tag('li', $options, \CHtml::link($label, $url, $linkOptions) . $items); } return \CHtml::tag('ul', array('class' => 'dropdown'), implode("\n", $li)); }
/** * Returns a generated LI tag item * @param array $item the item configuration * @return string the resulting li tag */ public function renderItem($item) { $content = ArrayHelper::getValue($item, 'content', ''); $caption = ArrayHelper::getValue($item, 'caption'); if ($caption !== null) { $caption = \CHtml::tag('div', array('class' => Enum::ORBIT_CAPTION), $caption); } return \CHtml::tag('li', array(), $content . $caption); }
/** * Renders a section item * @param array $item the section item * @return string the section result */ public function renderItem($item) { $sectionItem = array(); $sectionItem[] = \CHtml::tag('p', array('class' => 'title', 'data-section-title' => 'data-section-title'), \CHtml::link(ArrayHelper::getValue($item, 'label', 'Section Title'), '#')); $options = ArrayHelper::getValue($item, 'options', array()); Html::addCssClass($options, 'content'); ArrayHelper::addValue('data-section-content', 'data-section-content', $options); $sectionOptions = array(); if (ArrayHelper::getValue($item, 'active')) { ArrayHelper::addValue('class', 'active', $sectionOptions); } $sectionItem[] = \CHtml::tag('div', $options, ArrayHelper::getValue($item, 'content', 'Section Content')); return \CHtml::tag('section', $sectionOptions, implode("\n", $sectionItem)); }
/** * Renders a clearing (lightbox) item * @param array $item * @return string the resulting LI tag item */ public function renderItem($item) { $options = ArrayHelper::getValue($item, 'options', array()); if (isset($item['featured'])) { Html::addCssClass($this->htmlOptions, Enum::ClEARING_FEATURE); Html::addCssClass($options, Enum::CLEARING_FEATURE_IMG); } $imgOptions = array(); $imgOptions['src'] = ArrayHelper::getValue($item, 'th', '#'); $imgOptions['data-caption'] = ArrayHelper::getValue($item, 'caption', null); $imgOptions['class'] = 'th'; $url = ArrayHelper::getValue($item, 'img', '#'); return \CHtml::tag('li', $options, \CHtml::link(\CHtml::tag('img', $imgOptions), $url)); }
/** * Renders a widget's item * @param mixed $item the item to render * @return string the rendering result. * @throws InvalidConfigException */ protected function renderItem($item) { if (is_string($item)) { return $item; } if (!isset($item['label'])) { throw new InvalidConfigException("The 'label' option is required."); } $label = $this->encodeLabels ? \CHtml::encode($item['label']) : $item['label']; $options = ArrayHelper::getValue($item, 'options', array()); $items = ArrayHelper::getValue($item, 'items'); $url = \CHtml::normalizeUrl(ArrayHelper::getValue($item, 'url', '#')); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); if (ArrayHelper::getValue($item, Enum::STATE_ACTIVE)) { ArrayHelper::addValue('class', Enum::STATE_ACTIVE, $options); } if ($items !== null) { Html::addCssClass($options, Enum::DROPDOWN_HAS); if (is_array($items)) { $items = Nav::dropdown($items, $this->encodeLabels); } } return \CHtml::tag('li', $options, \CHtml::link($label, $url, $linkOptions) . $items); }
/** * Renders a single stop * @param array $stop the stop configuration * @return string the resulting li tag */ public function renderStop($stop) { $options = array(); $options['data-id'] = ArrayHelper::getValue($stop, 'id'); $options['data-text'] = ArrayHelper::getValue($stop, 'text'); $options['data-button'] = ArrayHelper::getValue($stop, 'button'); $options['data-class'] = ArrayHelper::getValue($stop, 'class'); $options['data-options'] = ArrayHelper::getValue($stop, 'options'); if ($options['data-options'] !== null) { $config = array(); foreach ($options['data-options'] as $key => $option) { $config[] = $key . ':' . $option; } $options['data-options'] = implode(';', $config); } $title = ArrayHelper::getValue($stop, 'title'); if (!empty($title)) { $title = "<h4>{$title}</h4>"; } $content = '<p>' . ArrayHelper::getValue($stop, 'body', '') . '</p>'; return \CHtml::tag('li', $options, $title . $content); }