bitprocessor = $callback; } // ################################################################### /** * Callback public function for the processing the entire page navigator. Needs * the signature: * public string callback(string $baseLink, integer $nextPage, integer $prevPage array $show['first'=>first page, 'last'=>last page, 'prev'=>previous page, 'next'=>next page], string $bits, Pagination $this) * * @param string Callback function */ public function setNavigatorProcessor($callback) { $this->pagenavprocessor = $callback; } // ################################################################### /** * Returns the current page number * * @return integer Current page */ public function getPage() { return $this->page; } // ################################################################### /** * Returns the current perpage value * * @return integer Current perpage */ public function getPerPage() { return $this->perpage; } // ################################################################### /** * Sets total * * @param integer Total number */ public function setTotal($total) { $this->total = $total; } // ################################################################### /** * Returns the number of pages to be in the navigator * * @param integer Number of pages */ public function getPageCount() { return $this->pagecount; } // ################################################################### /** * Sets pagelinks * * @param integer Number of page links */ public function setPageLinks($pagelinks) { $this->pagelinks = $pagelinks; } // ################################################################### /** * Sets pagevar * * @param string Page variable */ public function setPageVar($pagevar) { $this->pagevar = $pagevar; } // ################################################################### /** * Sets perpagevar * * @param string Per-page variable */ public function setPerPageVar($perpagevar) { $this->perpagevar = $perpagevar; } // ################################################################### /** * Sets maxperpage * * @param integer Maximum number per page */ public function setMaxPerPage($maxperpage) { $this->maxperpage = $maxperpage; } // ################################################################### /** * Sets defaultperpage * * @param integer Total number */ public function setDefaultPerPage($defaultperpage) { $this->defaultperpage = $defaultperpage; } // ################################################################### /** * Takes all of the information from the set() functions and then * prepares all of the data through verification */ public function processIncomingData() { $this->page = BSApp::$input->inputClean($this->pagevar, TYPE_INT); $this->perpage = BSApp::$input->inputClean($this->perpagevar, TYPE_INT); $this->pagelinks = BSApp::$input->clean($this->pagelinks, TYPE_INT); if ($this->page <= 0) { $this->page = 1; } if ($this->perpage <= 0) { $this->perpage = $this->defaultperpage; } if ($this->perpage > $this->maxperpage) { $this->perpage = $this->maxperpage; } $this->perpage = BSApp::$input->clean($this->perpage, TYPE_INT); } // ################################################################### /** * Takes the variables and splits up the pages */ public function splitPages() { $this->pagecount = ceil($this->total / $this->perpage); if ($this->pagelinks == 0) { $this->pagelinks = $this->pagecount; } } // ################################################################### /** * Returns the lower limit of the pages * * @param integer Page number * * @return integer Lower result limit */ public function fetchLimit($page = null) { if ($page === null) { $page = $this->page; } $limit = $page * $this->perpage; if ($page < 1) { $page = 1; $limit = 0; } else if ($page > $this->pagecount) { $page = $this->pagecount - 1; $limit = $this->total; } if ($limit < 0) { return 0; } else if ($limit > $this->total) { return $this->total; } else { return $limit; } } // ################################################################### /** * Constructs the page navigator * * @param string Base link path * @param bool Add a ? or a & to the path so it's link-friendly * * @return string Generated HTML page navigator */ public function constructPageNav($baselink, $addParam = true) { global $bugsys; // handle base link if ($addParam) { if (strpos($baselink, '?') === false) { $baselink .= '?'; } else if (!preg_match('#\?$#', $baselink) && !preg_match('#(&|&)$#', $baselink)) { $baselink .= '&'; } } // first page number in page nav $startpage = $this->page - $this->pagelinks; if ($startpage < 1) { $startpage = 1; } // last page number in page nav $endpage = $this->page + $this->pagelinks; if ($endpage > $this->pagecount) { $endpage = $this->pagecount; } // prev page in page nav $prevpage = $this->page - 1; if ($prevpage < 1) { $prevpage = 1; } // next page in page nav $nextpage = $this->page + 1; if ($nextpage > $this->pagecount) { $nextpage = $this->pagecount; } // show the prev page $show['prev'] = true; if ($this->page == $startpage) { $show['prev'] = false; } // show the next page $show['next'] = true; if ($this->page == $endpage) { $show['next'] = false; } // show the first page $show['first'] = false; if ($startpage > 1) { $show['first'] = true; } // show the last page $show['last'] = false; if ($endpage < $this->pagecount) { $show['last'] = true; } // construct the page bits $bits = ''; $call = $this->bitprocessor; for ($i = $startpage; $i <= $endpage; $i++) { if ($i == $this->page) { $nolink = true; } else { $nolink = false; } $bits .= $call($baselink, $nolink, $i, $this); } $call = $this->pagenavprocessor; return $call($baselink, $nextpage, $prevpage, $show, $bits, $this); } } ?>