Пример #1
0
 /**
  * Generates an image carousel.
  * @param array $items the item configurations.
  * @param array $htmlOptions additional HTML attributes.
  * @return string the generated carousel.
  */
 public static function carousel(array $items, $htmlOptions = array())
 {
     if (!empty($items)) {
         $id = BsArray::getValue('id', $htmlOptions, parent::ID_PREFIX . parent::$count++);
         BsArray::defaultValue('id', $id, $htmlOptions);
         $selector = '#' . $id;
         self::addCssClass('carousel', $htmlOptions);
         if (BsArray::popValue('slide', $htmlOptions, true)) {
             self::addCssClass('slide', $htmlOptions);
         }
         $interval = BsArray::popValue('data-interval', $htmlOptions);
         if ($interval) {
             $htmlOptions['data-interval'] = $interval;
         }
         $pause = BsArray::popValue('data-pause', $htmlOptions);
         if ($pause) {
             $htmlOptions['data-pause'] = $pause;
         }
         $indicatorOptions = BsArray::popValue('indicatorOptions', $htmlOptions, array());
         $innerOptions = BsArray::popValue('innerOptions', $htmlOptions, array());
         self::addCssClass('carousel-inner', $innerOptions);
         $prevOptions = BsArray::popValue('prevOptions', $htmlOptions, array());
         $prevLabel = BsArray::popValue('label', $prevOptions, '‹');
         $nextOptions = BsArray::popValue('nextOptions', $htmlOptions, array());
         $nextLabel = BsArray::popValue('label', $nextOptions, '›');
         $hidePrevAndNext = BsArray::popValue('hidePrevAndNext', $htmlOptions, false);
         $output = self::openTag('div', $htmlOptions);
         $output .= self::carouselIndicators($selector, count($items), $indicatorOptions);
         $output .= self::openTag('div', $innerOptions);
         foreach ($items as $i => $itemOptions) {
             if (isset($itemOptions['visible']) && $itemOptions['visible'] === false) {
                 continue;
             }
             if ($i === 0) {
                 // first item should be active
                 self::addCssClass('active', $itemOptions);
             }
             $content = BsArray::popValue('content', $itemOptions, '');
             $image = BsArray::popValue('image', $itemOptions, '');
             $imageOptions = BsArray::popValue('imageOptions', $itemOptions, array());
             $imageAlt = BsArray::popValue('alt', $imageOptions, '');
             if (!empty($image)) {
                 $content = parent::image($image, $imageAlt, $imageOptions);
             }
             $label = BsArray::popValue('label', $itemOptions);
             $caption = BsArray::popValue('caption', $itemOptions);
             $output .= self::carouselItem($content, $label, $caption, $itemOptions);
         }
         $output .= '</div>';
         if (!$hidePrevAndNext) {
             $output .= self::carouselPrevLink($prevLabel, $selector, $prevOptions);
             $output .= self::carouselNextLink($nextLabel, $selector, $nextOptions);
         }
         $output .= '</div>';
         return $output;
     }
     return '';
 }
Пример #2
0
 /**
  * Displays the first validation error for a model attribute.
  * @param CModel $model the data model
  * @param string $attribute the attribute name
  * @param array $htmlOptions additional HTML attributes to be rendered in the container div tag.
  * @param boolean $enableAjaxValidation whether to enable AJAX validation for the specified attribute.
  * @param boolean $enableClientValidation whether to enable client-side validation for the specified attribute.
  * @return string the validation result (error display or success message).
  */
 public function error($model, $attribute, $htmlOptions = array(), $enableAjaxValidation = true, $enableClientValidation = true)
 {
     if (!$this->enableAjaxValidation) {
         $enableAjaxValidation = false;
     }
     if (!$this->enableClientValidation) {
         $enableClientValidation = false;
     }
     if (!$enableAjaxValidation && !$enableClientValidation) {
         return BsHtml::error($model, $attribute, $htmlOptions);
     }
     $id = CHtml::activeId($model, $attribute);
     $inputID = BsArray::getValue('inputID', $htmlOptions, $id);
     unset($htmlOptions['inputID']);
     BsArray::defaultValue('id', $inputID . '_em_', $htmlOptions);
     $option = array('id' => $id, 'inputID' => $inputID, 'errorID' => $htmlOptions['id'], 'model' => get_class($model), 'name' => $attribute, 'enableAjaxValidation' => $enableAjaxValidation, 'inputContainer' => 'div.form-group', 'errorCssClass' => $this->errorMessageCssClass, 'successCssClass' => $this->successMessageCssClass);
     $optionNames = array('validationDelay', 'validateOnChange', 'validateOnType', 'hideErrorMessage', 'inputContainer', 'errorCssClass', 'successCssClass', 'validatingCssClass', 'beforeValidateAttribute', 'afterValidateAttribute');
     foreach ($optionNames as $name) {
         if (isset($htmlOptions[$name])) {
             $option[$name] = BsArray::popValue($name, $htmlOptions);
         }
     }
     if ($model instanceof CActiveRecord && !$model->isNewRecord) {
         $option['status'] = 1;
     }
     if ($enableClientValidation) {
         $validators = BsArray::getValue('clientValidation', $htmlOptions, array());
         $attributeName = $attribute;
         if (($pos = strrpos($attribute, ']')) !== false && $pos !== strlen($attribute) - 1) {
             $attributeName = substr($attribute, $pos + 1);
         }
         foreach ($model->getValidators($attributeName) as $validator) {
             if ($validator->enableClientValidation) {
                 if (($js = $validator->clientValidateAttribute($model, $attributeName)) != '') {
                     $validators[] = $js;
                 }
             }
         }
         if ($validators !== array()) {
             $option['clientValidation'] = "js:function(value, messages, attribute) {\n" . implode("\n", $validators) . "\n}";
         }
     }
     $html = BsHtml::error($model, $attribute, $htmlOptions);
     if ($html === '') {
         $htmlOptions['type'] = $this->helpType;
         BsHtml::addCssStyle('display:none', $htmlOptions);
         $html = BsHtml::help('', $htmlOptions);
     }
     $this->attributes[$inputID] = $option;
     return $html;
 }