<commit_before><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package		Koowa_Template
 * @subpackage	Helper
 * @copyright	Copyright (C) 2007 - 2010 <NAME>. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link     	http://www.nooku.org
 */

/**
 * Template Paginator Helper
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package		Koowa_Template
 * @subpackage	Helper
 */
class KTemplateHelperPaginator extends KTemplateHelperSelect
{
	/**
	 * 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);
    }

	/**
	 * Render item pagination
	 * 
	 * @param 	array 	An optional array with configuration options
	 * @return	string	Html
	 * @see  	http://developer.yahoo.com/ypatterns/navigation/pagination/
	 */
	public function pagination($config = array())
	{
		$config = new KConfig($config);
		$config->append(array(
			'total'   => 0,
			'display' => 4,
			'offset'  => 0,
			'limit'	  => 0,
			'attribs' => array('onchange' => 'this.form.submit();')
		));
	
		$this->_initialize($config);
        
		$html = '';
		$html .= '<style src="media://lib_koowa/css/koowa.css" />';

		$html .= '<div class="-koowa-pagination">';
		$html .= '<div class="limit">'.JText::_('Display NUM').' '.$this->limit($config).'</div>';
		$html .=  $this->_pages($this->_items($config));
		$html .= '<div class="count"> '.JText::_('Page').' '.$config->current.' '.JText::_('of').' '.$config->count.'</div>';
		$html .= '</div>';

		return $html;
	}
	
	/**
	 * Render a select box with limit values
	 *
	 * @param 	array 	An optional array with configuration options
	 * @return 	string	Html select box
	 */
	public function limit($config = array())
	{
		$config = new KConfig($config);
		$config->append(array(
			'limit'	  	=> 0,
			'attribs'	=> array(),
		));
		
		$html = '';
		
		$selected = '';
		foreach(array(10 => 10, 20 => 20, 50 => 50, 100 => 100) as $value => $text)<commit_msg>Added 'show_limit' and 'show_count' configuration options.<commit_after><?php
/**
 * @version		$Id$
 * @category	Koowa
 * @package		Koowa_Template
 * @subpackage	Helper
 * @copyright	Copyright (C) 2007 - 2010 <NAME>. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link     	http://www.nooku.org
 */

/**
 * Template Paginator Helper
 *
 * @author		<NAME> <<EMAIL>>
 * @category	Koowa
 * @package		Koowa_Template
 * @subpackage	Helper
 */
class KTemplateHelperPaginator extends KTemplateHelperSelect
{
	/**
	 * 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);
    }

	/**
	 * Render item pagination
	 * 
	 * @param 	array 	An optional array with configuration options
	 * @return	string	Html
	 * @see  	http://developer.yahoo.com/ypatterns/navigation/pagination/
	 */
	public function pagination($config = array())
	{
		$config = new KConfig($config);
		$config->append(array(
			'total'      => 0,
			'display'    => 4,
			'offset'     => 0,
			'limit'	     => 0,
			'attribs'    => array('onchange' => 'this.form.submit();'),
		    'show_limit' => true,
		    'show_count' => true
		));
	
		$this->_initialize($config);
        
		$html = '';
		$html .= '<style src="media://lib_koowa/css/koowa.css" />';

		$html .= '<div class="-koowa-pagination">';
		if($config->show_limit) {
		    $html .= '<div class="limit">'.JText::_('Display NUM').' '.$this->limit($config).'</div>';
		}
		$html .=  $this->_pages($this->_items($config));
		if($config->show_count) {
		    $html .= '<div class="count"> '.JText::_('Page').' '.$config->current.' '.JText::_('of').' '.$config->count.'</div>';
		}
		$html .= '</div>';

		return $html;
	}
	
	/**
	 * Render a select box with limit values
	 *
	 * @param 	array 	An optional array with configuration options
	 * @return 	string	Html select box
	 */
	public function limit($config = array())
	{
		$config = new KConfig($config);
		$config->append(array(
			'limit'	  	=> 0,
			'attribs'	=> array(),
		));
		
		$html = '';
		
		$selected = '';
		foreach(array(10 => 10, 20 => 20, 50 => 50, 100 => 100) as $value => $text)
{'fraction_non_alphanumeric': 0.17935463659147868, 'fraction_numerical': 0.013471177944862155, 'mean_word_length': 2.2444105691056913, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '820108', 'n_tokens_mistral': 2273, 'n_tokens_neox': 2029, 'n_words': 452}