4 * @package News_Paginate
5 * @copyright Copyright (c) 2008, Bellière Ludovic
6 * @license http://opensource.org/licenses/mit-license.php MIT license
10 * @author Bellière Ludovic
12 * @package News_Paginate
13 * @copyright Copyright (c) 2008, Bellière Ludovic
14 * @license http://opensource.org/licenses/mit-license.php MIT license
19 * Nombre d'éléments par page.
23 public $limit_by_page=10;
26 * Nombre d'éléments total
33 * Nombre total de page qui seront générées
37 public $number_of_pages;
40 * Variable a regarder pour connaître la page courrante.
44 protected $page_variable="p";
47 * Numéro de la page courrante
51 protected $current_page=1;
53 public function __construct($elements,$limit_by_page=10) {
54 $this->limit_by_page
= (int) $limit_by_page;
55 $this->elements
= (int) $elements;
56 self
::set_current_page();
59 public function paginate($pageurl) {
60 $this->number_of_pages
= ceil($this->elements
/ $this->limit_by_page
);
61 if ($this->number_of_pages
== 1) {
64 $pageurl = strpos($pageurl, '?') ?
$pageurl.'&' : $pageurl.'?';
66 $txt = ($this->current_page
=== 1) ?
'' : '< <a href="'.$pageurl.$this->page_variable
.'='.($this->current_page
-1).'">précédent</a> | ';
67 while($i < $this->number_of_pages
) {
68 if ($i == $this->current_page
) {
71 $txt.= '<a href="'.$pageurl.$this->page_variable
.'='.$i.'" class="paginator">page '.$i.'</a>, ';
75 return substr($txt,0,-2).(($this->number_of_pages
> $this->current_page
) ?
' | <a href="'.$pageurl.$this->page_variable
.'='.($this->current_page+
1).'">Suivant</a> > ':'').'.';
80 * Return the SQL LIMIT statement for a sql queries
82 public function get_sql_limit_statement() {
83 $lines = $this->limit_by_page
;
84 $offset = $this->limit_by_page
*($this->current_page
-1);
85 return "LIMIT $offset, $lines";
88 protected function set_current_page() {
89 if (empty($_GET['p'])) {
90 $this->current_page
= 1;
92 $this->current_page
= intval($_GET['p']);
96 public function get_current_page() {
97 return $this->current_page
;