* @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
}
}
- // ###################################################################
- /**
- * 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
{
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
*/
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)
{
$baselink .= '?';
}
- else if (!preg_match('#\?$#', $baselink) && !preg_match('#(&|&)$#', $baselink))
+ else if (!strpos($baselink, '#\?$#') && !strpos($baselink, '&'))
{
$baselink .= '&';
}
// construct the page bits
$bits = '';
- $call = $this->bitprocessor;
for ($i = $startpage; $i <= $endpage; $i++)
{
if ($i == $this->page)
$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);
}
}