Changeset 2717

Show
Ignore:
Timestamp:
05/29/2008 04:09:07 PM (5 months ago)
Author:
Geert
Message:

Pagination groups functionality added

Location:
trunk/system
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/config/pagination.php

    r2486 r2717  
    33 * @package  Pagination 
    44 * 
    5  * Views folder in which your pagination style templates reside. 
     5 * Pagination configuration is defined in groups which allows you to easily switch 
     6 * between different pagination settings for different website sections. 
     7 * 
     8 * Group Options: 
     9 *  directory      - Views folder in which your pagination style templates reside 
     10 *  style          - Pagination style template (matches view filename) 
     11 *  uri_segment    - URI segment (int or 'label') in which the current page number can be found 
     12 *  query_string   - Alternative to uri_segment: query string key that contains the page number 
     13 *  items_per_page - Number of items to display per page 
     14 *  auto_hide      - Automatically hides pagination for single pages 
    615 */ 
    7 $config['directory'] = 'pagination'; 
    8  
    9 /** 
    10  * Pagination style template (matches view filename). 
    11  */ 
    12 $config['style'] = 'classic'; 
    13  
    14 /** 
    15  * URI segment (or 'label') in which the current page number can be found. 
    16  */ 
    17 $config['uri_segment'] = 3; 
    18  
    19 /** 
    20  * Number of items to display per page. 
    21  */ 
    22 $config['items_per_page'] = 20; 
    23  
    24 /** 
    25  * Automatically hide pagination completely for single pages. 
    26  */ 
    27 $config['auto_hide'] = FALSE; 
     16$config['default'] = array 
     17( 
     18        'directory'      => 'pagination', 
     19        'style'          => 'classic', 
     20        'uri_segment'    => 3, 
     21        'query_string'   => '', 
     22        'items_per_page' => 20, 
     23        'auto_hide'      => FALSE, 
     24); 
  • trunk/system/i18n/en_US/pagination.php

    r1297 r2717  
    33$lang = array 
    44( 
     5        'undefined_group' => 'The %s group is not defined in your pagination configuration.', 
    56        'page'     => 'page', 
    67        'pages'    => 'pages', 
  • trunk/system/i18n/nl_NL/pagination.php

    r1524 r2717  
    33$lang = array 
    44( 
     5        'undefined_group' => 'De %s groep werd niet gedefinieerd in uw pagination configuratie.', 
    56        'page'     => 'pagina', 
    67        'pages'    => 'pagina\'s', 
  • trunk/system/libraries/Pagination.php

    r2665 r2717  
    2222        protected $auto_hide      = FALSE; 
    2323 
    24         // Automatically generated values 
     24        // Autogenerated values 
    2525        protected $url; 
    2626        protected $current_page; 
     
    3838         * Constructs and returns a new Pagination object. 
    3939         * 
    40          * @param   array  configuration 
     40         * @param   string  configuration group name 
     41         * @param   array   configuration items that overwrite group defaults 
    4142         * @return  object 
    4243         */ 
    43         public function factory($config = array()) 
    44         { 
    45                 return new Pagination($config); 
     44        public function factory($group = NULL, $config = array()) 
     45        { 
     46                return new Pagination($group, $config); 
    4647        } 
    4748 
     
    4950         * Constructs the Pagination object. 
    5051         * 
    51          * @param   array  configuration 
     52         * @param   string  configuration group name 
     53         * @param   array   configuration items that overwrite group defaults 
    5254         * @return  void 
    5355         */ 
    54         public function __construct($config = array()) 
    55         { 
    56                 // Load configuration 
    57                 $config += Config::item('pagination', FALSE, FALSE); 
    58  
     56        public function __construct($group = NULL, $config = array()) 
     57        { 
     58                // No group name given, only array with custom config 
     59                // Allows for backward compatibility as well 
     60                if (is_array($group)) 
     61                { 
     62                        $config = $group; 
     63                        $group = 'default'; 
     64                } 
     65                // Use default group 
     66                elseif ($group === NULL) 
     67                { 
     68                        $group = 'default'; 
     69                } 
     70 
     71                // Load and validate config group 
     72                if ( ! is_array($group_config = Config::item('pagination.'.$group))) 
     73                        throw new Kohana_Exception('pagination.undefined_group', $group); 
     74 
     75                // Merge custom config items with group defaults 
     76                $config += $group_config; 
     77 
     78                // Pagination setup 
    5979                $this->initialize($config); 
    6080