From a0613344165abaa516d4104b1c06a47423829a0e Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 28 Feb 2008 15:11:45 -0500 Subject: [PATCH] Making BSPagination an abstract class that people extend instead of using callback functions * Pagination.php --- Pagination.php | 161 +++++++++++++------------------------------------ 1 file changed, 43 insertions(+), 118 deletions(-) diff --git a/Pagination.php b/Pagination.php index 9ab0fdf..ae82425 100644 --- a/Pagination.php +++ b/Pagination.php @@ -38,73 +38,80 @@ * @package ISSO * */ -class BSPagination +abstract class BSPagination { /** * Current page number * @var integer */ - private $page; + protected $page; /** * Per-page value * @var integer */ - private $perpage; + protected $perpage; /** * Number of page links * @var integer */ - private $pagelinks; + protected $pagelinks; /** * Total number of results * @var integer */ - private $total; + protected $total; /** * Total number of pages * @var integer */ - private $pagecount; - - /** - * Name of page variable - * @var array - */ - private $pagevar = 'p'; - - /** - * Name of per-page variable - * @var integer - */ - private $perpagevar = 'pp'; + protected $pagecount; /** * Maximum number of per-page results * @var integer */ - private $maxperpage = 100; + protected $maxperpage = 100; /** * Default number of per-page results * @var integer */ - private $defaultperpage = 20; + protected $defaultperpage = 20; + // ################################################################### /** - * The processing callback public function for individual pagenav bits - * @var string - */ - private $bitprocessor = ':undefined:'; + * Callback public function for the processing of an indivdual page link + * + * @param string The base link + * @param boolean Wether or not the item is the current page + * @param integer Page number + * + * @return string Compiled HTML + */ + protected abstract function _bitProcessor($baselink, $isCurrent, $pagenumber); + // ################################################################### /** - * The processing callback public function for the entire pagenav system - * @var string - */ - private $pagenavprocessor = ':undefined:'; + * Callback public function for the processing the entire page navigator + * + * @param string The base link + * @param integer Next page number + * @param integer Previous page number + * @param array Show options: array('first' => (boolean)first page link, 'last' => boolean, 'prev' => boolean, 'next' => boolean) + * @param string Bits to process + * + * @return string Compiled HTML + */ + protected abstract function _navigationProcessor($baselink, $next, $prev, $show, $bits); + + /** + * Set the Pagination->perpage and Pagination->page variables + */ + protected abstract function _setVariables(); /** * Constructor @@ -117,32 +124,6 @@ class BSPagination } } - // ################################################################### - /** - * Callback public function for the processing of an indivdual page. Needs - * the signature: - * public string callback(string $baseLink, boolean $noLink, integer $pageNumber, Pagination $this) - * - * @param string Callback function - */ - public function setBitProcessor($callback) - { - $this->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 @@ -186,62 +167,7 @@ class BSPagination { 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 @@ -249,8 +175,9 @@ class BSPagination */ public function processIncomingData() { - $this->page = BSApp::$input->inputClean($this->pagevar, TYPE_INT); - $this->perpage = BSApp::$input->inputClean($this->perpagevar, TYPE_INT); + $this->_setVariables(); + $this->page = BSApp::$input->clean($this->page, TYPE_INT); + $this->perpage = BSApp::$input->clean($this->perpage, TYPE_INT); $this->pagelinks = BSApp::$input->clean($this->pagelinks, TYPE_INT); if ($this->page <= 0) @@ -343,7 +270,7 @@ class BSPagination { $baselink .= '?'; } - else if (!preg_match('#\?$#', $baselink) && !preg_match('#(&|&)$#', $baselink)) + else if (!strpos($baselink, '#\?$#') && !strpos($baselink, '&')) { $baselink .= '&'; } @@ -407,7 +334,6 @@ class BSPagination // construct the page bits $bits = ''; - $call = $this->bitprocessor; for ($i = $startpage; $i <= $endpage; $i++) { if ($i == $this->page) @@ -419,11 +345,10 @@ class BSPagination $nolink = false; } - $bits .= $call($baselink, $nolink, $i, $this); + $bits .= $this->_bitProcessor($baselink, $nolink, $i); } - - $call = $this->pagenavprocessor; - return $call($baselink, $nextpage, $prevpage, $show, $bits, $this); + + return $this->_navigationProcessor($baselink, $nextpage, $prevpage, $show, $bits); } } -- 2.43.5