summaryrefslogtreecommitdiffstats
path: root/system/libraries/Pagination.php
diff options
context:
space:
mode:
authoradmin <devnull@localhost>2006-10-21 21:44:22 +0200
committeradmin <devnull@localhost>2006-10-21 21:44:22 +0200
commite334c472fb4be44feec3a73402fc4a2b062cbfc0 (patch)
tree553f17d67e7ef652016ec85b2a576bb2210f0ff8 /system/libraries/Pagination.php
parentbd6bee75dd26ade1c8d9cfd104bb913065797c59 (diff)
Diffstat (limited to 'system/libraries/Pagination.php')
-rw-r--r--system/libraries/Pagination.php122
1 files changed, 61 insertions, 61 deletions
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 26fb93ee4..a004419d6 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -7,7 +7,7 @@
* @package CodeIgniter
* @author Rick Ellis
* @copyright Copyright (c) 2006, pMachine, Inc.
- * @license http://www.codeignitor.com/user_guide/license.html
+ * @license http://www.codeignitor.com/user_guide/license.html
* @link http://www.codeigniter.com
* @since Version 1.0
* @filesource
@@ -28,13 +28,13 @@ class CI_Pagination {
var $base_url = ''; // The page we are linking to
var $total_rows = ''; // Total number of items (database results)
- var $per_page = 10; // Max number of items you want shown per page
- var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
- var $cur_page = 0; // The current page being viewed
+ var $per_page = 10; // Max number of items you want shown per page
+ var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
+ var $cur_page = 0; // The current page being viewed
var $first_link = '&lsaquo; First';
var $next_link = '&gt;';
var $prev_link = '&lt;';
- var $last_link = 'Last &rsaquo;';
+ var $last_link = 'Last &rsaquo;';
var $uri_segment = 3;
var $full_tag_open = '';
var $full_tag_close = '';
@@ -57,15 +57,15 @@ class CI_Pagination {
* @access public
* @param array initialization parameters
*/
- function CI_Pagination($params = array())
- {
+ function CI_Pagination($params = array())
+ {
if (count($params) > 0)
{
$this->initialize($params);
}
log_message('debug', "Pagination Class Initialized");
- }
+ }
// --------------------------------------------------------------------
@@ -76,8 +76,8 @@ class CI_Pagination {
* @param array initialization parameters
* @return void
*/
- function initialize($params = array())
- {
+ function initialize($params = array())
+ {
if (count($params) > 0)
{
foreach ($params as $key => $val)
@@ -88,7 +88,7 @@ class CI_Pagination {
}
}
}
- }
+ }
// --------------------------------------------------------------------
@@ -98,34 +98,34 @@ class CI_Pagination {
* @access public
* @return string
*/
- function create_links()
- {
+ function create_links()
+ {
// If our item count or per-page total is zero there is no need to continue.
- if ($this->total_rows == 0 OR $this->per_page == 0)
- {
- return '';
- }
+ if ($this->total_rows == 0 OR $this->per_page == 0)
+ {
+ return '';
+ }
// Calculate the total number of pages
- $num_pages = ceil($this->total_rows / $this->per_page);
+ $num_pages = ceil($this->total_rows / $this->per_page);
- /*
+ /*
// Calculate the total number of pages
$num_pages = intval($this->total_rows / $this->per_page);
// Use modulus to see if our division has a remainder. If so, add one to our page number.
- if ($this->total_rows % $this->per_page)
+ if ($this->total_rows % $this->per_page)
{
$num_pages++;
}
*/
-
- // Is there only one page? Hm... nothing more to do here then.
- if ($num_pages == 1)
- {
- return '';
- }
-
+
+ // Is there only one page? Hm... nothing more to do here then.
+ if ($num_pages == 1)
+ {
+ return '';
+ }
+
// Determine the current page number.
$CI =& get_instance();
if ($CI->uri->segment($this->uri_segment) != 0)
@@ -140,35 +140,35 @@ class CI_Pagination {
$uri_page_number = $this->cur_page;
$this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
-
+
// Calculate the start and end numbers. These determine
// which number to start and end the digit links with
- $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;
- $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;
-
+ $start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;
+ $end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;
+
// Add a trailing slash to the base URL if needed
$this->base_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->base_url);
// And here we go...
- $output = '';
-
+ $output = '';
+
// Render the "First" link
- if ($this->cur_page > $this->num_links)
- {
- $output .= $this->first_tag_open.'<a href="'.$this->base_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
- }
-
+ if ($this->cur_page > $this->num_links)
+ {
+ $output .= $this->first_tag_open.'<a href="'.$this->base_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
+ }
+
// Render the "previous" link
- if (($this->cur_page - $this->num_links) >= 0)
- {
- $i = $uri_page_number - $this->per_page;
- if ($i == 0) $i = '';
- $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
- }
-
+ if (($this->cur_page - $this->num_links) >= 0)
+ {
+ $i = $uri_page_number - $this->per_page;
+ if ($i == 0) $i = '';
+ $output .= $this->prev_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
+ }
+
// Write the digit links
- for ($loop = $start -1; $loop <= $end; $loop++)
- {
+ for ($loop = $start -1; $loop <= $end; $loop++)
+ {
$i = ($loop * $this->per_page) - $this->per_page;
if ($i >= 0)
@@ -183,30 +183,30 @@ class CI_Pagination {
$output .= $this->num_tag_open.'<a href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;
}
}
- }
+ }
// Render the "next" link
- if ($this->cur_page < $num_pages)
- {
- $output .= $this->next_tag_open.'<a href="'.$this->base_url.($this->cur_page * $this->per_page).'">'.$this->next_link.'</a>'.$this->next_tag_close;
- }
+ if ($this->cur_page < $num_pages)
+ {
+ $output .= $this->next_tag_open.'<a href="'.$this->base_url.($this->cur_page * $this->per_page).'">'.$this->next_link.'</a>'.$this->next_tag_close;
+ }
// Render the "Last" link
- if (($this->cur_page + $this->num_links) < $num_pages)
- {
- $i = (($num_pages * $this->per_page) - $this->per_page);
- $output .= $this->last_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->last_link.'</a>'.$this->last_tag_close;
- }
-
- // Kill double slashes. Note: Sometimes we can end up with a double slash
+ if (($this->cur_page + $this->num_links) < $num_pages)
+ {
+ $i = (($num_pages * $this->per_page) - $this->per_page);
+ $output .= $this->last_tag_open.'<a href="'.$this->base_url.$i.'">'.$this->last_link.'</a>'.$this->last_tag_close;
+ }
+
+ // Kill double slashes. Note: Sometimes we can end up with a double slash
// in the penultimate link so we'll kill all double slashes.
- $output = preg_replace("#([^:])//+#", "\\1/", $output);
+ $output = preg_replace("#([^:])//+#", "\\1/", $output);
// Add the wrapper HTML if exists
$output = $this->full_tag_open.$output.$this->full_tag_close;
return $output;
- }
+ }
}
// END Pagination Class
?> \ No newline at end of file