From 5a0e046c7ba211bedc4ea17462720b12eb9aa6dd Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 25 Nov 2006 07:04:13 +0000 Subject: [PATCH] Completely overhauled the pagination framework module --- pagination.php | 133 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 115 insertions(+), 18 deletions(-) diff --git a/pagination.php b/pagination.php index 4c52748..a20d215 100644 --- a/pagination.php +++ b/pagination.php @@ -109,6 +109,20 @@ class Pagination */ var $defaultperpage = 20; + /** + * The processing callback function for individual pagenav bits + * @var string + * @access private + */ + var $bitprocessor = ':undefined:'; + + /** + * The processing callback function for the entire pagenav system + * @var string + * @access private + */ + var $pagenavprocessor = ':undefined:'; + // ################################################################### /** * Constructor @@ -127,6 +141,62 @@ class Pagination $this->__construct($registry); } + // ################################################################### + /** + * Callback function for the processing of an indivdual page. Needs + * the signature: + * public string callback(string $baseLink, boolean $noLink, integer $pageNumber, Pagination $this) + * + * @access public + * + * @param string Callback function + */ + function setBitProcessor($callback) + { + $this->bitprocessor = $callback; + } + + // ################################################################### + /** + * Callback 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) + * + * @access public + * + * @param string Callback function + */ + function setNavigatorProcessor($callback) + { + $this->pagenavprocessor = $callback; + } + + // ################################################################### + /** + * Returns the current page number + * + * @access public + * + * @return integer Current page + */ + function getPage() + { + return $this->page; + } + + // ################################################################### + /** + * Returns the current perpage value + * + * @access public + * + * @return integer Current perpage + */ + function getPerPage() + { + return $this->perpage; + } + // ################################################################### /** * Sets total @@ -140,6 +210,19 @@ class Pagination $this->total = $total; } + // ################################################################### + /** + * Returns the number of pages to be in the navigator + * + * @access public + * + * @param integer Number of pages + */ + function getPageCount() + { + return $this->pagecount; + } + // ################################################################### /** * Sets pagelinks @@ -205,35 +288,50 @@ class Pagination $this->defaultperpage = $defaultperpage; } + // ################################################################### /** - * Takes the variables and splits up the pages + * Takes all of the information from the set() functions and then + * prepares all of the data through verification * * @access public */ - function split_pages() + function processIncomingData() { $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->pagelinks, TYPE_INT); - + $this->pagelinks = $this->registry->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['maxpp']) + if ($this->perpage > $this->maxperpage) { - $this->perpage = $this->maxperpage['maxpp']; + $this->perpage = $this->maxperpage; } - + $this->perpage = $this->registry->clean($this->perpage, TYPE_INT); - + } + + // ################################################################### + /** + * Takes the variables and splits up the pages + * + * @access public + */ + function splitPages() + { $this->pagecount = ceil($this->total / $this->perpage); + if ($this->pagelinks == 0) + { + $this->pagelinks = $this->pagecount; + } } // ################################################################### @@ -246,7 +344,7 @@ class Pagination * * @return integer Lower result limit */ - function fetch_limit($page = null) + function fetchLimit($page = null) { if ($page === null) { @@ -290,7 +388,7 @@ class Pagination * * @return string Generated HTML page navigator */ - function construct_page_nav($baselink) + function constructPageNav($baselink) { global $bugsys; @@ -361,6 +459,8 @@ class Pagination } // construct the page bits + $bits = ''; + $call = $this->bitprocessor; for ($i = $startpage; $i <= $endpage; $i++) { if ($i == $this->page) @@ -372,14 +472,11 @@ class Pagination $nolink = false; } - eval('$pagebits[] .= "' . $this->registry->modules['template']->fetch('pagenav_bit') . '";'); + $bits .= $call($baselink, $nolink, $i, $this); } - - $pagebits = implode(",\n", $pagebits); - - eval('$pagenav = "' . $this->registry->modules['template']->fetch('pagenav') . '";'); - - return $pagenav; + + $call = $this->pagenavprocessor; + return $call($baselink, $nextpage, $prevpage, $show, $bits, $this); } } -- 2.22.5