Пример #1
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param 	object 	An optional KConfig object with configuration options
  * @return  void
  */
 protected function _initialize(KConfig $config)
 {
     if ($config->total != 0) {
         $config->limit = (int) max($config->limit, 1);
         $config->offset = (int) max($config->offset, 0);
         if ($config->limit > $config->total) {
             $config->offset = 0;
         }
         if (!$config->limit) {
             $config->offset = 0;
             $config->limit = $config->total;
         }
         $config->count = (int) ceil($config->total / $config->limit);
         if ($config->offset > $config->total) {
             $config->offset = ($config->count - 1) * $config->limit;
         }
         $config->current = (int) floor($config->offset / $config->limit) + 1;
     } else {
         $config->limit = 0;
         $config->offset = 0;
         $confgi->count = 0;
         $config->current = 0;
     }
     parent::_initialize($config);
 }
Пример #2
0
 /**
  * Generates an HTML radio list, Overriding Koowa to remove the <br>
  *
  * @param 	array 	An optional array with configuration options
  * @return	string	Html
  */
 public function radiolist($config = array())
 {
     $html = parent::radiolist($config);
     $html = explode(PHP_EOL, $html);
     unset($html[2]);
     unset($html[5]);
     return implode(PHP_EOL, $html);
 }
Пример #3
0
 /**
  * Search the mixin method map and call the method or trigger an error
  * 
  * This function check to see if the method exists in the mixing map if not
  * it will call the 'listbox' function. The method name will become the 'name'
  * in the config array.
  * 
  * This can be used to auto-magically create select filters based on the 
  * function name.
  *
  * @param  string   The function name
  * @param  array    The function arguments
  * @throws BadMethodCallException   If method could not be found
  * @return mixed The result of the function
  */
 public function __call($method, array $arguments)
 {
     if (!in_array($method, $this->getMethods())) {
         $config = $arguments[0];
         $config['name'] = KInflector::singularize(strtolower($method));
         return $this->_listbox($config);
     }
     return parent::__call($method, $arguments);
 }
Пример #4
0
 public function fetchElement($name, $value, &$node, $control_name)
 {
     $config = new KConfig();
     $config->append(array('name' => 'id', 'attribs' => array(), 'key' => 'id', 'text' => 'title', 'selected' => $value, 'translate' => false));
     $name = $config->name;
     $attribs = KHelperArray::toString($config->attribs);
     $options = array();
     foreach ($node->children() as $option) {
         $options[] = (object) array($config->key => $option['value'], $config->text => (string) $option);
     }
     $config->list = $options;
     $class = isset($node['class']) ? $node['class'] : 'value';
     $html = array('<ul id="' . $this->name . '_id" class="' . $class . '">');
     foreach ($config->list as $row) {
         $key = $row->{$config->key};
         $text = $config->translate ? JText::_($row->{$config->text}) : $row->{$config->text};
         $id = isset($row->id) ? $row->id : null;
         $extra = '';
         if ($config->selected instanceof KConfig) {
             foreach ($config->selected as $value) {
                 $sel = is_object($value) ? $value->{$config->key} : $value;
                 if ($key == $sel) {
                     $extra .= 'checked="checked"';
                     break;
                 }
             }
         } else {
             $extra .= $key == $config->selected ? 'checked="checked"' : '';
         }
         $html[] = '<li class="value">';
         $html[] = '<label for="' . $this->name . '_' . $key . '"><input type="checkbox" name="' . $this->name . '[]" id="' . $this->name . '_' . $key . '" value="' . $key . '" ' . $extra . ' ' . $attribs . ' />' . $text . '</label>';
         $html[] = '</li>';
     }
     $html[] = '</ul>';
     return implode(PHP_EOL, $html);
     $options = array();
     foreach ($node->children() as $option) {
         $val = (string) $option['value'];
         $text = (string) $option;
         $options[] = (object) array('value' => $val, 'text' => $text);
     }
     $vertical = isset($node['vertical']) ? ' vertical' : null;
     $html[] = '<ul class="group' . $vertical . '">';
     $realname = $this->field . '[' . $this->group . '][' . $name . ']';
     $idname = $this->field . '_' . $this->group . '_' . $name;
     $checklist = KTemplateHelperSelect::checklist($options, $realname, $value, array('id' => '{id}'), 'value', 'text');
     $search = array('for="' . $realname, 'id="' . $realname);
     $replace = array('for="' . $idname, 'id="' . $idname);
     $checklist = str_replace($search, $replace, $checklist);
     foreach (explode('</label>', $checklist) as $check) {
         $html[] = '<li class="value">';
         $html[] = $check;
         $html[] = '</label></li>';
     }
     $html[] = '</ul>';
     return implode($html);
 }
Пример #5
0
 /**
  * Ordering option list helper.
  *
  * @param Array $config An optional configuration object
  */
 public function ordering($config = array())
 {
     $config = new KConfig($config);
     $options = array();
     $orders = array('newest' => 'Newest first', 'oldest' => 'Oldest first', 'popular' => 'Most popular', 'alpha' => 'Alphabetical', 'category' => 'Section/Category');
     foreach ($orders as $value => $title) {
         $options[] = $this->option(array('value' => $value, 'text' => $title));
     }
     $config->append(array('options' => $options, 'name' => 'ordering', 'translate' => true))->append(array('selected' => $config->{$config->name}));
     return parent::optionlist($config);
 }
Пример #6
0
	public function booleanlist( $config = array())
	{
		$config = new KConfig($config);
		$config->append(array(
			'name'   	=> '',
			'attribs'	=> array(),
			'true'		=> 'yes',
			'false'		=> 'no',
			'selected'	=> null,
			'translate'	=> true
		));
		
		return parent::booleanlist($config);
	}
Пример #7
0
 /**
  * Search the mixin method map and call the method or trigger an error
  *
  * This function check to see if the method exists in the mixing map if not it will call the 'listbox' function.
  * The method name will become the 'name' in the config array.
  *
  * This can be used to auto-magically create select filters based on the function name.
  *
  * @param  string   $method The function name
  * @param  array    $arguments The function arguments
  * @throws BadMethodCallException   If method could not be found
  * @return mixed The result of the function
  */
 public function __call($method, $arguments)
 {
     if (!in_array($method, $this->getMethods())) {
         $config = $arguments[0];
         if (!isset($config['name'])) {
             $config['name'] = KStringInflector::singularize(strtolower($method));
         }
         return $this->_render($config);
     }
     return parent::__call($method, $arguments);
 }
Пример #8
0
 /**
  * Display a radio list for filtering the list based on specified filters
  *
  */
 public function filter($config = array())
 {
     $config = new KConfig($config);
     $config->append(array('name' => 'enabled'))->append(array('selected' => $config->state->{$config->name}, 'list' => array((object) array('id' => '', 'title' => JText::_('All')), (object) array('id' => '1', 'title' => JText::_('Enabled')), (object) array('id' => '0', 'title' => JText::_('Disabled')))));
     KFactory::get('admin::com.ninja.helper.default')->css('/select.css');
     $url = clone KRequest::url();
     $url->query[$config->name] = '';
     KFactory::get('lib.joomla.document')->addScriptDeclaration("\nwindow.addEvent('domready', function(){\n\t\$\$('[name=" . $config->name . "][checked]').getNext().addClass('selected');\n\tnew Element('label', {'class': 'divider'}).inject(\$('" . $config->name . "').getNext(), 'after');\n\t\$\$('[name=" . $config->name . "]').addEvent('change', function(){\n\t\tthis.getSiblings('label').removeClass('selected');\n\t\tthis.getNext().addClass('selected');\n\t\twindow.location.href = '{$url}'.replace('&" . $config->name . "=', '&" . $config->name . "='+this.get('value'));\n\t});\t\t\n});");
     return '<div class="ninja-filter ' . $config->name . '">' . KTemplateHelperSelect::radiolist($config) . '</div>';
 }