forked from getkirby-v1/toolkit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
031af4b
commit 6ba5471
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
class pager { | ||
|
||
static public $entries; | ||
static public $page; | ||
static public $limit; | ||
static public $pages; | ||
|
||
function setup($entries, $page, $limit) { | ||
self::$entries = $entries; | ||
self::$limit = $limit; | ||
self::$pages = ($entries > 0) ? ceil($entries / $limit) : 0; | ||
self::$page = self::sanitize($page, self::$pages); | ||
} | ||
|
||
function get() { | ||
return self::$page; | ||
} | ||
|
||
function next() { | ||
return (self::$page+1 < self::$pages) ? self::$page+1 : self::$page; | ||
} | ||
|
||
function previous() { | ||
return (self::$page-1 >= 1) ? self::$page-1 : self::$page; | ||
} | ||
|
||
function count() { | ||
return self::$pages; | ||
} | ||
|
||
function sanitize($page, $pages) { | ||
$page = intval($page); | ||
if($page > $pages) $page = $pages; | ||
if($page < 1) $page = 1; | ||
return $page; | ||
} | ||
|
||
function db() { | ||
return (self::$page-1)*self::$limit; | ||
} | ||
|
||
} | ||
|
||
?> |