From 140b65d5b5035f7100424fb1800d08a696ecfa0c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 12 Jan 2006 19:02:51 +0000 Subject: [PATCH] Adding pagination class... it kind of works --- pagination.php | 362 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 362 insertions(+) create mode 100644 pagination.php diff --git a/pagination.php b/pagination.php new file mode 100644 index 0000000..69f507c --- /dev/null +++ b/pagination.php @@ -0,0 +1,362 @@ + array(REQ_YES, null, false), + 'pagelinks' => array(REQ_YES, null, false), + 'pagevar' => array(REQ_YES, null, false), + 'perpagevar' => array(REQ_YES, null, false), + 'maxperpage' => array(REQ_YES, null, true), + 'defaultperpage' => array(REQ_YES, null, true) + ); + + // ################################################################### + /** + * Constructor + */ + function __construct(&$registry) + { + $this->registry =& $registry; + } + + // ################################################################### + /** + * (PHP 4) Constructor + */ + function Pagination(&$registry) + { + $this->__construct($registry); + } + + /** + * Constructor: sanitize incoming variables + * + * @param string Name of page number variable + * @param string Name of per-page variable + */ + function Pagination($page, $perpage) + { + global $bugsys; + + } + + // ################################################################### + /** + * Sets an ISSO field + * + * @access public + * + * @param string Field name + * @param mixed Value of the field + */ + function set($name, $value) + { + $this->registry->do_set($name, $value, 'pagination'); + } + + // ################################################################### + /** + * Gets an ISSO field + * + * @access public + * + * @param string Field name + * + * @return mixed Value of the field + */ + function get($fieldname) + { + return $this->registry->do_get($fieldname, 'pagination'); + } + + /** + * Takes the variables and splits up the pages + * + * @access public + */ + function split_pages() + { + $this->page = $this->registry->input_clean($this->pagevar, TYPE_INT); + $this->perpage = $this->registry->input_clean($this->perpagevar, TYPE_INT); + $this->pagelinks = $this->registry->input_clean($this->pagelinkx, TYPE_INT); + + if ($this->page <= 0) + { + $this->page = 1; + } + + if ($this->perpage <= 0) + { + $this->perpage = $this->defaultperpage; + } + if ($this->perpage > $this->maxperpage['maxpp']) + { + $this->perpage = $this->maxperpage['maxpp']; + } + + $this->perpage = $this->registry->clean($this->perpage, TYPE_INT); + + $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; + } + + $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 + * + * @access public + * + * @param string Base link path + * + * @return string Generated HTML page navigator + */ + function construct_page_nav($baselink) + { + global $bugsys; + + // handle base link + if (strpos($baselink, '?') === false) + { + $baselink .= '?'; + } + else if (!preg_match('#\?$#', $baselink) AND !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 + for ($i = $startpage; $i <= $endpage; $i++) + { + if ($i == $this->page) + { + $nolink = true; + } + else + { + $nolink = false; + } + + eval('$pagebits[] .= "' . $bugsys->template->fetch('pagenav_bit') . '";'); + } + + $pagebits = implode(",\n", $pagebits); + + eval('$pagenav = "' . $bugsys->template->fetch('pagenav') . '";'); + + return $pagenav; + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.43.5