From c78a0c4fdf916d39e49ac758c6730c8611fb1caa Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 22 Aug 2005 00:23:11 +0000 Subject: [PATCH] r356: Pagination engine works --- includes/class_pagination.php | 230 ++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 includes/class_pagination.php diff --git a/includes/class_pagination.php b/includes/class_pagination.php new file mode 100644 index 0000000..30bcb3e --- /dev/null +++ b/includes/class_pagination.php @@ -0,0 +1,230 @@ +page = intval($bugsys->in["$page"]); + $this->perpage = intval($bugsys->in["$perpage"]); + $this->pagelinks = intval($bugsys->options['pagelinks']); + + if ($this->page <= 0) + { + $this->page = 1; + } + + if ($this->perpage <= 0) + { + $this->perpage = $bugsys->options['defaultpp']; + } + if ($this->perpage > $bugsys->options['maxpp']) + { + $this->perpage = $bugsys->options['maxpp']; + } + } + + /** + * Takes the variables and splits up the pages + * + * @access protected + */ + function split_pages() + { + $this->pagecount = ceil($this->total / $this->perpage); + } + + /** + * Returns the lower limit of the pages + * + * @access public + * + * @param integer Page number + * + * @return integer Lower result limit + */ + function fetch_limit($page = null) + { + if ($page === null) + { + $page = $this->page; + } + + if ($page < 1) + { + $page = 1; + } + else if ($page > $this->pagecount) + { + $page = $this->pagecount - 1; + } + + $limit = $page * $this->perpage; + + if ($limit < 0) + { + return 0; + } + else if ($limit > $this->total) + { + return $this->total; + } + else + { + return $limit; + } + } + + /** + * Constructs the page navigator + * + * @access public + * + * @return string Generated HTML page navigator + */ + function construct_page_nav() + { + // 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 + $doprev = true; + if ($this->page == $startpage) + { + $doprev = false; + } + + // show the next page + $donext = true; + if ($this->page == $endpage) + { + $donext = false; + } + + // show the first page + $dofirst = false; + if ($startpage > 1) + { + $dofirst = true; + } + + // show the last page + $dolast = false; + if ($endpage < $this->pagecount) + { + $dolast = true; + } + + // add the special links + if ($dofirst) + { + $pages[] = 'first'; + } + if ($doprev) + { + $pages[] = 'prev'; + } + + // construct the page bits + for ($i = $startpage; $i <= $endpage; $i++) + { + $pages[] = ($i == $this->page ? "$i" : $i); + } + + // last special links + if ($donext) + { + $pages[] = 'next'; + } + if ($dolast) + { + $pages[] = 'last'; + } + + return $pages; + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.43.5