From a01924d2cc2d63d2bddbee85a18b423b88a9b19e Mon Sep 17 00:00:00 2001 From: Takayuki Sakai Date: Fri, 13 Jun 2014 02:01:52 +0900 Subject: Make num_links=0 in pagination library possible to configure --- system/libraries/Pagination.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 5b9bfcb5d..d079d835d 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -393,9 +393,9 @@ class CI_Pagination { // Check the user defined number of links. $this->num_links = (int) $this->num_links; - if ($this->num_links < 1) + if ($this->num_links < 0) { - show_error('Your number of links must be a positive number.'); + show_error('Your number of links must be a non-negative number.'); } // Keep any existing query string items. @@ -535,11 +535,14 @@ class CI_Pagination { // Render the "First" link. if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { - // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); + if (($this->num_links === 0 && $this->cur_page < 3) !== true) + { + // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); - $output .= $this->first_tag_open.'_attr_rel('start').'>' + $output .= $this->first_tag_open.'_attr_rel('start').'>' .$this->first_link.''.$this->first_tag_close; + } } // Render the "Previous" link. @@ -611,12 +614,15 @@ class CI_Pagination { // Render the "Last" link if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links) < $num_pages) { - $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; + if (($this->num_links === 0 && ($this->cur_page + 1) >= $num_pages) !== true) + { + $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); - $output .= $this->last_tag_open.'' - .$this->last_link.''.$this->last_tag_close; + $output .= $this->last_tag_open.'' + .$this->last_link.''.$this->last_tag_close; + } } // Kill double slashes. Note: Sometimes we can end up with a double slash -- cgit v1.2.3-24-g4f1b From 1240b6a04ee4e6a200cc882481f09fce6a7eb4fc Mon Sep 17 00:00:00 2001 From: Takayuki Sakai Date: Fri, 13 Jun 2014 18:12:02 +0900 Subject: Revert "Make num_links=0 in pagination library possible to configure" This reverts commit a01924d2cc2d63d2bddbee85a18b423b88a9b19e. --- system/libraries/Pagination.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d079d835d..5b9bfcb5d 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -393,9 +393,9 @@ class CI_Pagination { // Check the user defined number of links. $this->num_links = (int) $this->num_links; - if ($this->num_links < 0) + if ($this->num_links < 1) { - show_error('Your number of links must be a non-negative number.'); + show_error('Your number of links must be a positive number.'); } // Keep any existing query string items. @@ -535,14 +535,11 @@ class CI_Pagination { // Render the "First" link. if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) { - if (($this->num_links === 0 && $this->cur_page < 3) !== true) - { - // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); + // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); - $output .= $this->first_tag_open.'_attr_rel('start').'>' + $output .= $this->first_tag_open.'_attr_rel('start').'>' .$this->first_link.''.$this->first_tag_close; - } } // Render the "Previous" link. @@ -614,15 +611,12 @@ class CI_Pagination { // Render the "Last" link if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links) < $num_pages) { - if (($this->num_links === 0 && ($this->cur_page + 1) >= $num_pages) !== true) - { - $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; + $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; - $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); + $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, (int) $i); - $output .= $this->last_tag_open.'' - .$this->last_link.''.$this->last_tag_close; - } + $output .= $this->last_tag_open.'' + .$this->last_link.''.$this->last_tag_close; } // Kill double slashes. Note: Sometimes we can end up with a double slash -- cgit v1.2.3-24-g4f1b From 8bc5903ce7d4694f50c2cd02036a788c88c134f2 Mon Sep 17 00:00:00 2001 From: Takayuki Sakai Date: Fri, 13 Jun 2014 18:38:05 +0900 Subject: Make 'num_links=0' configuration available in Pagination library Changed conditions when making 'first' and 'last' links --- system/libraries/Pagination.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 5b9bfcb5d..3c8baac36 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -393,9 +393,9 @@ class CI_Pagination { // Check the user defined number of links. $this->num_links = (int) $this->num_links; - if ($this->num_links < 1) + if ($this->num_links < 0) { - show_error('Your number of links must be a positive number.'); + show_error('Your number of links must be a non-negative number.'); } // Keep any existing query string items. @@ -533,7 +533,7 @@ class CI_Pagination { $output = ''; // Render the "First" link. - if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1)) + if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1 + ! $this->num_links)) { // Take the general parameters, and squeeze this pagination-page attr in for JS frameworks. $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, 1); @@ -609,7 +609,7 @@ class CI_Pagination { } // Render the "Last" link - if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links) < $num_pages) + if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links + ! $this->num_links) < $num_pages) { $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page; -- cgit v1.2.3-24-g4f1b