Skip to content

Commit

Permalink
new plugin: pager
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Mar 22, 2010
1 parent 031af4b commit 6ba5471
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions plugins/pager.php
@@ -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;
}

}

?>

0 comments on commit 6ba5471

Please sign in to comment.