session_start() ?>
/*
* paginator.php - Created on 16-Nov-2006
*
* a class which will will output pagination
* information where it's needed ...
*
* Params for the constructor
* currentPage = int
* totalResults = int
* pageName = string (pagename to be used in URLs)
* pageSize = number of items to be shown per page
*
* functions
* getCurrentPage - returns page number (integer)
* isFirstPage - returns boolean
* isLastPage - returns boolean
* createPagination - returns string containing hyperlinks to page numbers
*
*/
class paginator {
public $separator = " | ";
public $bLinkChar = "<";
public $fLinkChar = ">";
function __construct($currentPage,$totalResults,$pageName,$pageSize=10,$prevArrow="[<< Prev]", $nxtArrow="[Next >>]") {
// Constructor info here
// Note, I added ltArrow and gtArrow to display the next and prev page indicators, the default is
// text-based as per the constructor. If the user specifies ANYTHING else it'll be taken as a call
// to an image ...
$this->currentPage = $currentPage;
$this->totalResults = $totalResults;
$this->pageName = $pageName;
$this->pageSize = $pageSize;
if (($prevArrow != "[<< Prev]") and ($prevArrow != "")){
$this->prevArrow = "";
} else {
$this->prevArrow = $prevArrow;
}
if (($nxtArrow != "[Next >>]") and ($nxtArrow != "")) {
$this->nxtArrow = "";
} else {
$this->nxtArrow = $nxtArrow;
}
}
function getCurrentPage() {
return $this->currentPage;
}
function isFirstPage() {
if ($this->currentPage ==1) {
return TRUE;
} else {
return FALSE;
}
}
function isLastPage() {
if (($this->currentPage*$this->pageSize) >= $this->totalResults) {
return TRUE;
} else {
return FALSE;
}
}
// UrlString *must* be passed in, will generate it at page level and send it over...
function createPagination($urlString="") {
$prevPage = ($this->currentPage < 2)? 1 : $this->currentPage-1;
$nextPage = (($this->currentPage*$this->pageSize) < $this->totalResults)? $this->currentPage+1 : ($this->totalResults / $this->pageSize);
if ($this->totalResults <= $this->pageSize) {
return (""); // If the numItems doesn't exceed the pagesize then pagination isn't necessary, return NOWT!
}
$this->prevArrow = ($this->currentPage > 0)? "pageName."/".$urlString."&pn=".($prevPage-1)."\">".$this->prevArrow."" : "";
$this->nextArrow = ((($this->currentPage+1) * $this->pageSize) <= $this->totalResults)? "pageName."/".$urlString."&pn=".($nextPage+1)."\">".$this->nxtArrow."" : "";
// finally, list the pages ...
$maxPages = (($this->totalResults % $this->pageSize) == 0) ? ($this->totalResults / $this->pageSize) : ($this->totalResults / $this->pageSize) + 1;
$pageString = "";
for ($loopVar=1; $loopVar <= $maxPages; $loopVar++) {
$tUrlString = $urlString; // temp var, otherwise it concetenates the page nums
$tUrlString .= ($tUrlString == "")? "pn=".$loopVar : "&pn=".$loopVar; // if urlString is empty donlt start with an amp ...
$displayPageNo = (($this->currentPage+1) == $loopVar)? "$loopVar" : "".$loopVar."";
$pageString .= $displayPageNo.$this->separator;
}
// Now bung it all together ...
// Quick check to suppress arrows for first/last pages
$this->prevArrow = ($this->currentPage == 0)? "" : $this->prevArrow;
$this->nextArrow = ($this->currentPage == $maxPages)? "" : $this->nextArrow;
$paginator = " ".$this->prevArrow." ".$this->separator.$pageString." ".$this->nextArrow;
return($paginator);
}
}
?>You must be registered or logged in to view the items you have listed