HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbActiveForm.php
Go to the documentation of this file.
1 <?php
72 class TbActiveForm extends CActiveForm {
73 
74  // Allowed form types.
75  const TYPE_VERTICAL = 'vertical';
76  const TYPE_INLINE = 'inline';
77  const TYPE_HORIZONTAL = 'horizontal';
78 
79  protected static $typeClasses = array (
80  self::TYPE_VERTICAL => '',
81  self::TYPE_INLINE => '-inline',
82  self::TYPE_HORIZONTAL => '-horizontal',
83  );
89 
94  public $prependCssClass = 'input-group';
95 
100  public $appendCssClass = 'input-group';
101 
106  public $addOnCssClass = 'input-group-addon';
107 
112  public $addOnTag = 'span';
113 
118  public $addOnWrapperTag = 'div';
119 
124  public $hintCssClass = 'help-block';
125 
130  public $hintTag = 'span';
131 
136  public $showErrors = true;
137 
142  public function init() {
143 
144  self::addCssClass($this->htmlOptions, 'form' . self::$typeClasses[$this->type]);
145 
146  $this->errorMessageCssClass = 'help-block error';
147 
148  $this->clientOptions['errorCssClass'] = 'has-error';
149  $this->clientOptions['successCssClass'] = 'has-success';
150  $this->clientOptions['inputContainer'] = 'div.form-group';
151 
152  parent::init();
153  }
154 
167  public function errorSummary($models, $header = null, $footer = null, $htmlOptions = array()) {
168 
169  if (!isset($htmlOptions['class'])) {
170  $htmlOptions['class'] = 'alert alert-block alert-danger';
171  }
172 
173  return parent::errorSummary($models, $header, $footer, $htmlOptions);
174  }
175 
191  public function urlFieldGroup($model, $attribute, $options = array()) {
192 
193  $this->initOptions($options);
194  $widgetOptions = $options['widgetOptions'];
195 
196  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
197 
198  $fieldData = array(array($this, 'urlField'), array($model, $attribute, $widgetOptions['htmlOptions']));
199 
200  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
201  }
202 
218  public function emailFieldGroup($model, $attribute, $options = array()) {
219 
220  $this->initOptions($options);
221  $widgetOptions = $options['widgetOptions'];
222 
223  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
224 
225  $fieldData = array(array($this, 'emailField'), array($model, $attribute, $widgetOptions['htmlOptions']));
226 
227  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
228  }
229 
245  public function numberFieldGroup($model, $attribute, $options = array()) {
246 
247  $this->initOptions($options);
248  $widgetOptions = $options['widgetOptions'];
249 
250  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
251 
252  $fieldData = array(array($this, 'numberField'), array($model, $attribute, $widgetOptions['htmlOptions']));
253 
254  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
255  }
256 
272  public function rangeFieldGroup($model, $attribute, $options = array()) {
273 
274  $this->initOptions($options);
275  $widgetOptions = $options['widgetOptions'];
276 
277  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
278 
279  $fieldData = array(array($this, 'rangeField'), array($model, $attribute, $widgetOptions['htmlOptions']));
280 
281  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
282  }
283 
299  public function dateFieldGroup($model, $attribute, $options = array()) {
300 
301  $this->initOptions($options);
302  $widgetOptions = $options['widgetOptions'];
303 
304  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
305 
306  $fieldData = array(array($this, 'dateField'), array($model, $attribute, $widgetOptions['htmlOptions']));
307 
308  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
309  }
310 
326  public function timeFieldGroup($model, $attribute, $options = array()) {
327 
328  $this->initOptions($options);
329  $widgetOptions = $options['widgetOptions'];
330 
331  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
332 
333  $fieldData = array(array($this, 'timeField'), array($model, $attribute, $widgetOptions['htmlOptions']));
334 
335  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
336  }
337 
353  public function telFieldGroup($model, $attribute, $options = array()) {
354 
355  $this->initOptions($options);
356  $widgetOptions = $options['widgetOptions'];
357 
358  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
359 
360  $fieldData = array(array($this, 'telField'), array($model, $attribute, $widgetOptions['htmlOptions']));
361 
362  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
363  }
364 
380  public function textFieldGroup($model, $attribute, $options = array()) {
381 
382  $this->initOptions($options);
383  $widgetOptions = $options['widgetOptions'];
384 
385  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
386 
387  $fieldData = array(array($this, 'textField'), array($model, $attribute, $widgetOptions['htmlOptions']));
388 
389  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
390  }
391 
406  public function searchFieldGroup($model, $attribute, $options = array()) {
407 
408  $this->initOptions($options);
409  $widgetOptions = $options['widgetOptions'];
410 
411  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
412 
413  $fieldData = array(array($this, 'searchField'), array($model, $attribute, $widgetOptions['htmlOptions']));
414 
415  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
416  }
417 
433  public function passwordFieldGroup($model, $attribute, $options = array()) {
434 
435  $this->initOptions($options);
436  $this->addCssClass($options['widgetOptions']['htmlOptions'], 'form-control');
437 
438  $fieldData = array(array($this, 'passwordField'), array($model, $attribute, $options['widgetOptions']['htmlOptions']));
439 
440  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
441  }
442 
458  public function textAreaGroup($model, $attribute, $options = array()) {
459 
460  $this->initOptions($options);
461  $this->addCssClass($options['widgetOptions']['htmlOptions'], 'form-control');
462 
463  $fieldData = array(array($this, 'textArea'), array($model, $attribute, $options['widgetOptions']['htmlOptions']));
464 
465  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
466  }
467 
483  public function fileFieldGroup($model, $attribute, $options = array()) {
484 
485  $this->initOptions($options);
486  $widgetOptions = $options['widgetOptions'];
487 
488  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
489 
490  $fieldData = array(array($this, 'fileField'), array($model, $attribute, $widgetOptions['htmlOptions']));
491 
492  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
493  }
494 
510  public function radioButtonGroup($model, $attribute, $options = array()) {
511 
512  $this->initOptions($options);
513  $widgetOptions = $options['widgetOptions']['htmlOptions'];
514 
515  self::addCssClass($options['labelOptions'], 'radio');
516  if( $this->type == self::TYPE_INLINE || (isset($options['inline']) && $options['inline']) )
517  self::addCssClass($options['labelOptions'], 'radio-inline');
518 
519  $field = $this->radioButton($model, $attribute, $widgetOptions);
520  if ((!array_key_exists('uncheckValue', $widgetOptions) || isset($widgetOptions['uncheckValue']))
521  && preg_match('/<input.*?type="hidden".*?>/', $field, $matches)
522  ) {
523  $hiddenField = $matches[0];
524  $field = str_replace($hiddenField, '', $field);
525  }
526 
527  $realAttribute = $attribute;
528  CHtml::resolveName($model, $realAttribute);
529 
530  ob_start();
531  if (isset($hiddenField)) echo $hiddenField;
532  echo CHtml::tag('label', $options['labelOptions'], false, false);
533  echo $field;
534  if (isset($options['label'])) {
535  if ($options['label'])
536  echo $options['label'];
537  } else
538  echo $model->getAttributeLabel($realAttribute);
539  echo CHtml::closeTag('label');
540  $fieldData = ob_get_clean();
541 
542  $widgetOptions['label'] = '';
543 
544  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
545  }
546 
562  public function checkboxGroup($model, $attribute, $options = array()) {
563 
564  $this->initOptions($options);
565 
566  if ($this->type == self::TYPE_INLINE)
567  self::addCssClass($options['labelOptions'], 'inline');
568 
569  $field = $this->checkbox($model, $attribute, $options['widgetOptions']['htmlOptions']);
570  if ((!array_key_exists('uncheckValue', $options['widgetOptions']) || isset($options['widgetOptions']['uncheckValue']))
571  && preg_match('/<input.*?type="hidden".*?>/', $field, $matches)
572  ) {
573  $hiddenField = $matches[0];
574  $field = str_replace($hiddenField, '', $field);
575  }
576 
577  $realAttribute = $attribute;
578  CHtml::resolveName($model, $realAttribute);
579 
580  ob_start();
581  echo '<div class="checkbox">';
582  if (isset($hiddenField)) echo $hiddenField;
583  echo CHtml::tag('label', $options['labelOptions'], false, false);
584  echo $field;
585  if (isset($options['label'])) {
586  if ($options['label'])
587  echo $options['label'];
588  } else
589  echo ' '.$model->getAttributeLabel($realAttribute);
590  echo CHtml::closeTag('label');
591  echo '</div>';
592  $fieldData = ob_get_clean();
593 
594  $options['label'] = '';
595 
596  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
597  }
598 
615  public function dropDownListGroup($model, $attribute, $options = array()) {
616 
617  $this->initOptions($options, true);
618  $widgetOptions = $options['widgetOptions'];
619 
620  // if(!isset($widgetOptions['data']))
621  // throw new CException('$options["widgetOptions"]["data"] must exist');
622 
623  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
624 
625  $fieldData = array(array($this, 'dropDownList'), array($model, $attribute, $widgetOptions['data'], $widgetOptions['htmlOptions']));
626 
627  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
628  }
629 
646  public function listBoxGroup($model, $attribute, $options = array()) {
647 
648  $this->initOptions($options, true);
649  $widgetOptions = $options['widgetOptions'];
650 
651  // if(!isset($widgetOptions['data']))
652  // throw new CException('$options["widgetOptions"]["data"] must exist');
653 
654  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
655 
656  $fieldData = array(array($this, 'listBox'), array($model, $attribute, $widgetOptions['data'], $widgetOptions['htmlOptions']));
657 
658  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
659  }
660 
677  public function checkboxListGroup($model, $attribute, $options = array()) {
678 
679  $this->initOptions($options, true);
680 
681  $widgetOptions = $options['widgetOptions']['htmlOptions'];
682 
683  // if(!isset($options['widgetOptions']['data']))
684  // throw new CException('$options["widgetOptions"]["data"] must exist');
685 
686  if (!isset($widgetOptions['labelOptions']['class']))
687  $widgetOptions['labelOptions']['class'] = 'checkbox';
688 
689  if(isset($options['inline']) && $options['inline'])
690  $widgetOptions['labelOptions']['class'] = 'checkbox-inline';
691 
692  if (!isset($widgetOptions['template']))
693  $widgetOptions['template'] = '{beginLabel}{input}{labelTitle}{endLabel}';
694 
695  if (!isset($widgetOptions['separator']))
696  $widgetOptions['separator'] = "\n";
697 
698  $data = $options['widgetOptions']['data'];
699 
700  $fieldData = array(array($this, 'checkboxList'), array($model, $attribute, $data, $widgetOptions));
701 
702  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
703  }
704 
721  public function radioButtonListGroup($model, $attribute, $options = array()) {
722 
723  $this->initOptions($options, true);
724 
725  $widgetOptions = $options['widgetOptions']['htmlOptions'];
726 
727  // if(!isset($options['widgetOptions']['data']))
728  // throw new CException('$options["widgetOptions"]["data"] must exist');
729 
730  if (!isset($widgetOptions['labelOptions']['class']))
731  $widgetOptions['labelOptions']['class'] = 'radio';
732 
733  if(isset($options['inline']) && $options['inline'])
734  $widgetOptions['labelOptions']['class'] = 'checkbox-inline';
735 
736  if (!isset($widgetOptions['template']))
737  $widgetOptions['template'] = '{beginLabel}{input}{labelTitle}{endLabel}';
738 
739  if (!isset($widgetOptions['separator']))
740  $widgetOptions['separator'] = "\n";
741 
742  $data = $options['widgetOptions']['data'];
743 
744  $fieldData = array(array($this, 'radioButtonList'), array($model, $attribute, $data, $widgetOptions));
745 
746  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
747  }
748 
764  public function switchGroup($model, $attribute, $options = array()) {
765 
766  return $this->widgetGroupInternal('booster.widgets.TbSwitch', $model, $attribute, $options);
767  }
768 
784  public function datePickerGroup($model, $attribute, $options = array()) {
785 
786  return $this->widgetGroupInternal('booster.widgets.TbDatePicker', $model, $attribute, $options);
787  }
788 
804  public function dateRangeGroup($model, $attribute, $options = array()) {
805 
806  return $this->widgetGroupInternal('booster.widgets.TbDateRangePicker', $model, $attribute, $options);
807  }
808 
824  public function timePickerGroup($model, $attribute, $options = array()) {
825 
826  return $this->widgetGroupInternal('booster.widgets.TbTimePicker', $model, $attribute, $options);
827  }
828 
844  public function dateTimePickerGroup($model, $attribute, $options = array()) {
845 
846  return $this->widgetGroupInternal('booster.widgets.TbDateTimePicker', $model, $attribute, $options);
847  }
848 
864  public function select2Group($model, $attribute, $options = array()) {
865 
866  return $this->widgetGroupInternal('booster.widgets.TbSelect2', $model, $attribute, $options);
867  }
868 
884  public function redactorGroup($model, $attribute, $options = array()) {
885 
886  return $this->widgetGroupInternal('booster.widgets.TbRedactorJs', $model, $attribute, $options);
887  }
888 
904  public function html5EditorGroup($model, $attribute, $options = array()) {
905 
906  return $this->widgetGroupInternal('booster.widgets.TbHtml5Editor', $model, $attribute, $options);
907  }
908 
924  public function markdownEditorGroup($model, $attribute, $options = array()) {
925 
926  return $this->widgetGroupInternal('booster.widgets.TbMarkdownEditor', $model, $attribute, $options);
927  }
928 
944  public function ckEditorGroup($model, $attribute, $options = array()) {
945 
946  return $this->widgetGroupInternal('booster.widgets.TbCKEditor', $model, $attribute, $options);
947  }
948 
964  public function typeAheadGroup($model, $attribute, $options = array()) {
965 
966  return $this->widgetGroupInternal('booster.widgets.TbTypeahead', $model, $attribute, $options);
967  }
968 
984  public function maskedTextFieldGroup($model, $attribute, $options = array()) {
985 
986  return $this->widgetGroupInternal('CMaskedTextField', $model, $attribute, $options);
987  }
988 
1004  public function colorPickerGroup($model, $attribute, $options = array()) {
1005 
1006  return $this->widgetGroupInternal('booster.widgets.TbColorPicker', $model, $attribute, $options);
1007  }
1008 
1027  public function captchaGroup($model, $attribute, $htmlOptions = array(), $options = array()) {
1028 
1029  $this->initOptions($options);
1030  $widgetOptions = $options['widgetOptions'];
1031 
1032  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
1033 
1034  $fieldData = $this->textField($model, $attribute, $widgetOptions['htmlOptions']);
1035  unset($widgetOptions['htmlOptions']);
1036  $fieldData .= '<div class="captcha">' . $this->owner->widget('CCaptcha', $widgetOptions, true) . '</div>';
1037 
1038  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
1039  }
1040 
1056  public function passFieldGroup($model, $attribute, $options = array()) {
1057 
1058  return $this->widgetGroupInternal('booster.widgets.TbPassfield', $model, $attribute, $options);
1059  }
1060 
1073  public function customFieldGroup($fieldData, $model, $attribute, $options = array()) {
1074 
1075  $this->initOptions($options);
1076 
1077  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
1078  }
1079 
1095  public function widgetGroup($className, $model, $attribute, $options = array()) {
1096 
1097  $this->initOptions($options);
1098  $widgetOptions = isset($options['widgetOptions']) ? $options['widgetOptions'] : null;
1099 
1100  $fieldData = array(array($this->owner, 'widget'), array($className, $widgetOptions, true));
1101 
1102  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
1103  }
1104 
1115  protected function widgetGroupInternal($className, &$model, &$attribute, &$options) {
1116  // if(empty($options['widgetOptions']['mask'])) exit;
1117  $this->initOptions($options);
1118  $widgetOptions = $options['widgetOptions'];
1119  $widgetOptions['model'] = $model;
1120  $widgetOptions['attribute'] = $attribute;
1121 
1122  $this->addCssClass($widgetOptions['htmlOptions'], 'form-control');
1123 
1124  $fieldData = array(array($this->owner, 'widget'), array($className, $widgetOptions, true));
1125 
1126  return $this->customFieldGroupInternal($fieldData, $model, $attribute, $options);
1127  }
1128 
1141  protected function customFieldGroupInternal(&$fieldData, &$model, &$attribute, &$options) {
1142 
1143  $this->setDefaultPlaceholder($fieldData);
1144 
1145  ob_start();
1146  switch ($this->type) {
1147  case self::TYPE_HORIZONTAL:
1148  $this->horizontalGroup($fieldData, $model, $attribute, $options);
1149  break;
1150 
1151  case self::TYPE_VERTICAL:
1152  $this->verticalGroup($fieldData, $model, $attribute, $options);
1153  break;
1154 
1155  case self::TYPE_INLINE:
1156  $this->inlineGroup($fieldData, $model, $attribute, $options);
1157  break;
1158 
1159  default:
1160  throw new CException('Invalid form type');
1161  }
1162 
1163  return ob_get_clean();
1164  }
1165 
1171  protected function setDefaultPlaceholder(&$fieldData) {
1172 
1173  if(!is_array($fieldData)
1174  || empty($fieldData[0][1]) /* 'textField' */
1175  || !is_array($fieldData[1]) /* ($model, $attribute, $htmlOptions) */
1176  )
1177  return;
1178 
1179  $model = $fieldData[1][0];
1180  if(!$model instanceof CModel)
1181  return;
1182 
1183  $attribute = $fieldData[1][1];
1184  if(!empty($fieldData[1][3]) && is_array($fieldData[1][3])) {
1185  /* ($model, $attribute, $data, $htmlOptions) */
1186  $htmlOptions = &$fieldData[1][3];
1187  } else {
1188  /* ($model, $attribute, $htmlOptions) */
1189  $htmlOptions = &$fieldData[1][2];
1190  }
1191  if (!isset($htmlOptions['placeholder'])) {
1192  $htmlOptions['placeholder'] = $model->getAttributeLabel($attribute);
1193  }
1194 
1195  }
1196 
1205  protected function horizontalGroup(&$fieldData, &$model, &$attribute, &$options) {
1206 
1207  $groupOptions = isset($options['groupOptions']) ? $options['groupOptions']: array(); // array('class' => 'form-group');
1208  self::addCssClass($groupOptions, 'form-group');
1209 
1210  if ($model->hasErrors($attribute))
1211  self::addCssClass($groupOptions, 'has-error');
1212 
1213  echo CHtml::openTag('div', $groupOptions);
1214 
1215  self::addCssClass($options['labelOptions'], 'col-sm-3 control-label');
1216  if (isset($options['label'])) {
1217  if (!empty($options['label'])) {
1218  echo CHtml::label($options['label'], CHtml::activeId($model, $attribute), $options['labelOptions']);
1219  } else {
1220  echo '<span class="col-sm-3"></span>';
1221  }
1222  } else {
1223  echo $this->labelEx($model, $attribute, $options['labelOptions']);
1224  }
1225 
1226  // TODO: is this good to be applied in vertical and inline?
1227  if(isset($options['wrapperHtmlOptions']) && !empty($options['wrapperHtmlOptions']))
1228  $wrapperHtmlOptions = $options['wrapperHtmlOptions'];
1229  else
1230  $wrapperHtmlOptions = $options['wrapperHtmlOptions'] = array();
1231  $this->addCssClass($wrapperHtmlOptions, 'col-sm-9');
1232  echo CHtml::openTag('div', $wrapperHtmlOptions);
1233 
1234  if (!empty($options['prepend']) || !empty($options['append'])) {
1235  $this->renderAddOnBegin($options['prepend'], $options['append'], $options['prependOptions']);
1236  }
1237 
1238  if (is_array($fieldData)) {
1239  echo call_user_func_array($fieldData[0], $fieldData[1]);
1240  } else {
1241  echo $fieldData;
1242  }
1243 
1244  if (!empty($options['prepend']) || !empty($options['append'])) {
1245  $this->renderAddOnEnd($options['append'], $options['appendOptions']);
1246  }
1247 
1248  if ($this->showErrors && $options['errorOptions'] !== false) {
1249  echo $this->error($model, $attribute, $options['errorOptions'], $options['enableAjaxValidation'], $options['enableClientValidation']);
1250  }
1251 
1252  if (isset($options['hint'])) {
1253  self::addCssClass($options['hintOptions'], $this->hintCssClass);
1254  echo CHtml::tag($this->hintTag, $options['hintOptions'], $options['hint']);
1255  }
1256 
1257  echo '</div></div>'; // controls, form-group
1258  }
1259 
1269  protected function verticalGroup(&$fieldData, &$model, &$attribute, &$options) {
1270 
1271  $groupOptions = isset($options['groupOptions']) ? $options['groupOptions']: array();
1272  self::addCssClass($groupOptions, 'form-group');
1273 
1274  if ($model->hasErrors($attribute))
1275  self::addCssClass($groupOptions, 'has-error');
1276 
1277  echo CHtml::openTag('div', $groupOptions);
1278 
1279  self::addCssClass($options['labelOptions'], 'control-label');
1280  if (isset($options['label'])) {
1281  if (!empty($options['label'])) {
1282  echo CHtml::label($options['label'], CHtml::activeId($model, $attribute), $options['labelOptions']);
1283  }
1284  } else {
1285  echo $this->labelEx($model, $attribute, $options['labelOptions']);
1286  }
1287 
1288  if (!empty($options['prepend']) || !empty($options['append'])) {
1289  $this->renderAddOnBegin($options['prepend'], $options['append'], $options['prependOptions']);
1290  }
1291 
1292  if (is_array($fieldData)) {
1293  echo call_user_func_array($fieldData[0], $fieldData[1]);
1294  } else {
1295  echo $fieldData;
1296  }
1297 
1298  if (!empty($options['prepend']) || !empty($options['append'])) {
1299  $this->renderAddOnEnd($options['append'], $options['appendOptions']);
1300  }
1301 
1302  if ($this->showErrors && $options['errorOptions'] !== false) {
1303  echo $this->error($model, $attribute, $options['errorOptions'], $options['enableAjaxValidation'], $options['enableClientValidation']);
1304  }
1305 
1306  if (isset($options['hint'])) {
1307  self::addCssClass($options['hintOptions'], $this->hintCssClass);
1308  echo CHtml::tag($this->hintTag, $options['hintOptions'], $options['hint']);
1309  }
1310 
1311  echo '</div>';
1312  }
1313 
1322  protected function inlineGroup(&$fieldData, &$model, &$attribute, &$options) {
1323 
1324  echo '<div class="form-group">';
1325 
1326  if (!empty($options['prepend']) || !empty($options['append']))
1327  $this->renderAddOnBegin($options['prepend'], $options['append'], $options['prependOptions']);
1328 
1329  if (is_array($fieldData)) {
1330  echo call_user_func_array($fieldData[0], $fieldData[1]);
1331  } else {
1332  echo $fieldData;
1333  }
1334 
1335  if (!empty($options['prepend']) || !empty($options['append']))
1336  $this->renderAddOnEnd($options['append'], $options['appendOptions']);
1337 
1338  if ($this->showErrors && $options['errorOptions'] !== false) {
1339  echo $this->error($model, $attribute, $options['errorOptions'], $options['enableAjaxValidation'], $options['enableClientValidation']);
1340  }
1341 
1342  echo "</div>\r\n";
1343  }
1344 
1352  protected function renderAddOnBegin($prependText, $appendText, $prependOptions) {
1353 
1354  $wrapperCssClass = array();
1355  if (!empty($prependText))
1356  $wrapperCssClass[] = $this->prependCssClass;
1357  if (!empty($appendText))
1358  $wrapperCssClass[] = $this->appendCssClass;
1359 
1360  echo CHtml::tag($this->addOnWrapperTag, array('class' => implode(' ', $wrapperCssClass)), false, false);
1361  if (!empty($prependText)) {
1362  if (isset($prependOptions['isRaw']) && $prependOptions['isRaw']) {
1363  echo $prependText;
1364  } else {
1365  self::addCssClass($prependOptions, $this->addOnCssClass);
1366  echo CHtml::tag($this->addOnTag, $prependOptions, $prependText);
1367  }
1368  }
1369  }
1370 
1377  protected function renderAddOnEnd($appendText, $appendOptions) {
1378 
1379  if (!empty($appendText)) {
1380  if (isset($appendOptions['isRaw']) && $appendOptions['isRaw']) {
1381  echo $appendText;
1382  } else {
1383  self::addCssClass($appendOptions, $this->addOnCssClass);
1384  echo CHtml::tag($this->addOnTag, $appendOptions, $appendText);
1385  }
1386  }
1387 
1388  echo CHtml::closeTag($this->addOnWrapperTag);
1389  }
1390 
1394  protected function initOptions(&$options, $initData = false) {
1395 
1396  if (!isset($options['groupOptions']))
1397  $options['groupOptions'] = array();
1398 
1399  if (!isset($options['labelOptions']))
1400  $options['labelOptions'] = array();
1401 
1402  if (!isset($options['widgetOptions']))
1403  $options['widgetOptions'] = array();
1404 
1405  if (!isset($options['widgetOptions']['htmlOptions']))
1406  $options['widgetOptions']['htmlOptions'] = array();
1407 
1408  if($initData && !isset($options['widgetOptions']['data']))
1409  $options['widgetOptions']['data'] = array();
1410 
1411  if (!isset($options['errorOptions']))
1412  $options['errorOptions'] = array();
1413 
1414  if (!isset($options['prependOptions']))
1415  $options['prependOptions'] = array();
1416 
1417  if (!isset($options['prepend']))
1418  $options['prepend'] = null;
1419 
1420  if (!isset($options['appendOptions']))
1421  $options['appendOptions'] = array();
1422 
1423  if (!isset($options['append']))
1424  $options['append'] = null;
1425 
1426  if(!isset($options['enableAjaxValidation']))
1427  $options['enableAjaxValidation'] = true;
1428 
1429  if(!isset($options['enableClientValidation']))
1430  $options['enableClientValidation'] = true;
1431  }
1432 
1439  protected static function addCssClass(&$htmlOptions, $class) {
1440 
1441  if (empty($class)) {
1442  return;
1443  }
1444 
1445  if (isset($htmlOptions['class'])) {
1446  $htmlOptions['class'] .= ' ' . $class;
1447  } else {
1448  $htmlOptions['class'] = $class;
1449  }
1450  }
1451 }