Skip to content

Commit

Permalink
Fix indentation
Browse files Browse the repository at this point in the history
Replaced tabs with spaces and wrapped lines under 80 characters.
  • Loading branch information
simonewebdesign committed Dec 29, 2012
1 parent 2fd36ca commit a3be0b1
Show file tree
Hide file tree
Showing 2 changed files with 326 additions and 307 deletions.
39 changes: 22 additions & 17 deletions library/classes/Paginator.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
/** Paginator.php
* A convenient class to paginate an arbitrary number of elements.
* A convenient class for paginating an arbitrary number of elements.
* Required parameters:
@param $elements the total number of elements to paginate.
@param $current_page the current page.
* Optional parameters:
@param $elements_per_page number of desired elements per page.
* For the paginate() function is also required the URL, that must respect this format: http://example.com/elements.php?page=$1 (where $1 is the placeholder for page).
* For the paginate() function is also required the URL, that must respect this
format:
http://example.com/elements.php?page=$1 (where $1 is the placeholder for page).
* @version 1.2 - 28/08/2012
* @author Simone <hello@simonewebdesign.it>
*/
Expand All @@ -17,9 +19,9 @@ class Paginator {
* [LIMIT {[offset,] row_count | row_count OFFSET offset}]
*/
var $offset = 0; // where to start displaying elements
var $elements_per_page = 0; // limit
var $elements_per_page = 0; // limit

var $page = 0; // current page
var $page = 0; // current page
var $pages = 0; // all pages
var $elements = 0; // all elements
var $displayed_elements = 0; // elements in the current page
Expand All @@ -30,19 +32,18 @@ class Paginator {
function setElements($elements) {
$this->elements = $elements;
}

function setElementsPerPage($elements_per_page) {
$this->elements_per_page = $elements_per_page;
}

function setPage($current_page=1) {
// paginate
$this->page = (int) ($current_page > 0 ? $current_page : 1);
$this->offset = (int) $this->page * $this->elements_per_page - $this->elements_per_page;
$this->offset = (int) $this->page * $this->elements_per_page
- $this->elements_per_page;
$this->pages = (int) ceil( $this->elements / $this->elements_per_page );
$this->displayed_elements = $this->page == $this->pages ? $this->elements % $this->elements_per_page : $this->elements_per_page;
$this->displayed_elements = $this->page == $this->pages ? $this->elements
% $this->elements_per_page : $this->elements_per_page;
}

function setURL($url) {
$this->url = $url;
}
Expand Down Expand Up @@ -84,12 +85,14 @@ function paginate() {
if ($this->elements > $this->elements_per_page) {
if ($this->page > 0) {
if ($this->page > 1) {
// we are not in the first page, so we print the first navigation arrows
// we aren't in the first page so we print the 1st navigation arrows
$html .= '<li>';
$html .= '<a href="' . $this->URLreplacedWithPage(1) . '"> &lt;&lt; </a>'; // first page
$html .= '<a href="' . $this->URLreplacedWithPage(1)
. '"> &lt;&lt; </a>'; // first page
$html .= '</li>';
$html .= '<li>';
$html .= '<a href="' . $this->URLreplacedWithPage($this->page - 1) . '"> &lt; </a>'; // previous page
$html .= '<a href="' . $this->URLreplacedWithPage($this->page - 1)
. '"> &lt; </a>'; // previous page
$html .= '</li>';
}

Expand All @@ -105,18 +108,20 @@ function paginate() {
}

if ($this->page < $this->pages) {
// we are not in the last page, so we print the last navigation arrows
// we aren't in the last page so we print the last navigation arrows
$html .= '<li>';
$html .= '<a href="' . $this->URLreplacedWithPage($this->page + 1) . '"> &gt; </a>'; // next page
$html .= '<a href="' . $this->URLreplacedWithPage($this->page + 1)
. '"> &gt; </a>'; // next page
$html .= '</li>';
$html .= '<li>';
$html .= '<a href="' . $this->URLreplacedWithPage($this->pages) . '"> &gt;&gt; </a>'; // last page
$html .= '<a href="' . $this->URLreplacedWithPage($this->pages)
. '"> &gt;&gt; </a>'; // last page
$html .= '</li>';
}
}
}
$html .= '</ul>';
$html .= '</div>';
return $html;
} // end paginate
} // end Paginator
} // end paginate function
} // end Paginator class
Loading

0 comments on commit a3be0b1

Please sign in to comment.