Exemplo n.º 1
0
 /**
  * Shows the field in the edit entry or add entry form
  * @param bool $return return or display directly
  * @return string
  */
 public function field($return = false)
 {
     if (!$this->enabled) {
         return false;
     }
     $class = $this->required ? $this->cssClass . ' required' : $this->cssClass;
     $params = array('class' => $class . ' checkbox');
     $values = array();
     if (count($this->options)) {
         foreach ($this->options as $option) {
             $values[$option['id']] = $option['label'];
         }
     }
     $selected = $this->getRaw();
     if (is_array($selected) && !is_string($selected) && count($selected)) {
         $selected = array_merge($selected, array_keys($selected));
     }
     if ($selected == null && $this->defaultValue) {
         $selected = explode(',', $this->defaultValue);
         $selected = array_map('trim', $selected);
     }
     $list = SPHtml_Input::checkBoxGroup($this->nid, $values, $this->nid, $selected, $params, $this->labelSite, true);
     $field = null;
     if (count($list)) {
         $c = 0;
         foreach ($list as $box) {
             $field .= '<div class="spFieldCheckbox"';
             if ($this->optWidth) {
                 $field .= ' style="width:' . $this->optWidth . 'px;"';
             }
             $field = $field . '>' . $box . '</div>';
             $field .= "\n";
             if ($this->optInLine) {
                 if (!(++$c % $this->optInLine)) {
                     $field .= "\n<div class=\"clearfix\"></div>\n";
                 }
             }
         }
         $field = "<div id=\"{$this->nid}\" class=\"{$class}\">{$field}\n<div class=\"clearfix\"></div>\n</div>";
     }
     if (!$return) {
         echo $field;
     } else {
         return $field;
     }
 }
Exemplo n.º 2
0
 /**
  * Shows the field in the search form
  * @param bool $return return or display directly
  * @return string
  */
 public function searchForm($return = false)
 {
     $data = $this->getValues();
     $field = null;
     switch ($this->searchMethod) {
         default:
         case 'general':
             $field = false;
             break;
         case 'chbx':
             $list = SPHtml_Input::checkBoxGroup($this->nid, $data, $this->nid, $this->_selected, array('class' => $this->cssClass . ' ' . Sobi::Cfg('search.form_checkbox_def_css', 'SPSearchChbx')), $this->labelSite, true);
             if (count($list)) {
                 $c = 0;
                 foreach ($list as $box) {
                     $box = '<div class="spFieldCheckbox" style="width:' . $this->optWidth . 'px;">' . $box . '</div>';
                     $field .= "\n" . $box;
                     if (!(++$c % $this->optInLine)) {
                         $field .= "\n<div class=\"clearfix\"></div>\n";
                     }
                 }
                 $field = "<div id=\"{$this->nid}\" >{$field}</div>";
                 $field .= "\n<div class=\"clearfix\"></div>\n";
             }
             break;
         case 'radio':
             $field = $this->getField($this->cssClass . ' ' . Sobi::Cfg('search.form_radio_def_css', 'SPSearchRadio'), $this->_selected);
             $field .= "\n<div class=\"clearfix\"></div>\n";
             break;
         case 'select':
         case 'mselect':
             $params = array('id' => $this->nid, 'size' => $this->searchMethod == 'mselect' ? $this->optInLine : 1, 'class' => $this->cssClass . ' ' . Sobi::Cfg('search.form_list_def_css', 'SPSearchSelect'));
             $data = array_merge(array('' => Sobi::Txt('FD.SEARCH_SELECT_LIST', array('name' => $this->name))), $data);
             $field = SPHtml_Input::select($this->nid, $data, $this->_selected, $this->searchMethod == 'mselect', $params);
             break;
     }
     return $field;
 }