示例#1
0
 public function getInput()
 {
     // Load javascript
     JHtml::_('jquery.framework');
     $document = JFactory::getDocument();
     $document->addScript(JURI::root(true) . '/media/k2app/assets/js/fields.js?v=3.0.0');
     // Set values if are not set
     if (!is_array($this->value)) {
         $this->value = array();
     }
     if (!isset($this->value['enabled'])) {
         $this->value['enabled'] = '0';
     }
     if (!isset($this->value['categories'])) {
         $this->value['categories'] = '';
     }
     if (!isset($this->value['recursive'])) {
         $this->value['recursive'] = '';
     }
     // Get some variables from XML
     $this->multiple = (bool) $this->element['k2multiple'];
     $this->recursive = (string) $this->element['k2recursive'];
     $this->mode = (string) $this->element['k2mode'];
     $this->size = (int) $this->element['size'];
     // Build attributes string
     $attributes = '';
     if ($this->multiple) {
         $attributes .= ' multiple="multiple"';
     }
     if ($this->size) {
         $attributes .= ' size="' . $this->size . '"';
     }
     if ($this->mode == 'menu') {
         $attributes .= ' data-mode="k2categoriesmenu"';
     }
     // Init output
     $output = '';
     // First show the category filter switch for multiple instances
     if ($this->multiple) {
         $options = array();
         $options[] = JHtml::_('select.option', '0', JText::_('K2_ALL'));
         $options[] = JHtml::_('select.option', '1', JText::_('K2_SELECT'));
         $output .= K2HelperHTML::radiolist($options, $this->name . '[enabled]', $this->value['enabled'], false, 'data-categories="' . $this->name . '[categories][]"');
         $placeholder = null;
     } else {
         $output .= '<input type="hidden" name="' . $this->name . '[enabled]" value="1" />';
         $placeholder = 'K2_NONE_ONSELECTLISTS';
     }
     // Then the categories list
     $output .= K2HelperHTML::categories($this->name . '[categories][]', $this->value['categories'], $placeholder, null, $attributes);
     // And finally the recursive switch
     if ($this->recursive == 'select') {
         $options = array();
         $options[] = JHtml::_('select.option', '1', JText::_('K2_YES'));
         $options[] = JHtml::_('select.option', '0', JText::_('K2_NO'));
         $output .= '<label>' . JText::_('K2_APPLY_RECUSRIVELY') . '</label>' . K2HelperHTML::radiolist($options, $this->name . '[recursive]', $this->value['recursive'], true);
     } else {
         $output .= '<input type="hidden" name="' . $this->name . '[recursive]" value="' . $this->recursive . '" />';
     }
     // Return
     return $output;
 }
示例#2
0
 public static function categories($name = 'catid', $value = null, $none = false, $exclude = null, $attributes = '', $recursive = false, $valueProperty = 'id', $inheritance = false, $batch = false)
 {
     $model = K2Model::getInstance('Categories', 'K2Model');
     $model->setState('sorting', 'ordering');
     $rows = $model->getRows();
     $options = array();
     if ($none) {
         $noneValue = $none === 'K2_LEAVE_UNCHANGED' ? '' : '0';
         $options[] = JHtml::_('select.option', $noneValue, JText::_($none));
     }
     if ($inheritance) {
         $options[] = JHtml::_('select.option', '1', JText::_('K2_FROM_K2_CATEGORY_PARAMETERS'));
     }
     if ($batch) {
         $options[] = JHtml::_('select.option', '1', JText::_('K2_NONE'));
     }
     foreach ($rows as $row) {
         if ($exclude != $row->id) {
             $title = str_repeat('-', intval($row->level) - 1) . $row->title;
             if ($row->state == -1) {
                 $title .= JText::_('K2_TRASHED_CATEGORY_NOTICE');
             } else {
                 if ($row->state == 0) {
                     $title .= JText::_('K2_UNPUBLISHED_CATEGORY_NOTICE');
                 }
             }
             $optionValue = $row->{$valueProperty};
             $options[] = JHtml::_('select.option', $optionValue, $title);
         }
     }
     $output = JHtml::_('select.genericlist', $options, $name, $attributes, 'value', 'text', $value);
     if ($recursive) {
         $options = array();
         $options[] = JHtml::_('select.option', '0', JText::_('K2_NO'));
         $options[] = JHtml::_('select.option', '1', JText::_('K2_YES'));
         $output .= '<label>' . JText::_($recursive->label) . '</label>' . K2HelperHTML::radiolist($options, $recursive->name, $recursive->value, true);
     }
     return $output;
 }