/*=====================================================================*\
|| ###################################################################
|| # Blue Static ISSO Framework
-|| # Copyright ©2002-[#]year[#] Blue Static
+|| # Copyright (c)2005-2009 Blue Static
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| # the Free Software Foundation; version 2 of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\*=====================================================================*/
/**
-* Pagination System (Pagination.php)
-*
-* @package ISSO
-*/
+ * Pagination System (Pagination.php)
+ *
+ * @package ISSO
+ */
/**
-* Pagination System
-*
-* On many pages, it is necessary to limit the amount of records to display.
-* Using this class, you can set the maximum and minimum values to display,
-* and then the input variables for page number and perpage. This will
-* then create a page navigator and manage the SQL LIMIT statements.
-*
-* @author Blue Static
-* @copyright Copyright ©2002 - [#]year[#], Blue Static
-* @version $Revision$
-* @package ISSO
-*
-*/
-class BSPagination
+ * Pagination System
+ *
+ * On many pages, it is necessary to limit the amount of records to display.
+ * Using this class, you can set the maximum and minimum values to display,
+ * and then the input variables for page number and perpage. This will
+ * then create a page navigator and manage the SQL LIMIT statements.
+ *
+ * @author Blue Static
+ * @copyright Copyright (c)2005 - 2009, Blue Static
+ * @package ISSO
+ *
+ */
+abstract class BSPagination
{
/**
- * Current page number
- * @var integer
- */
- private $page;
+ * Current page number
+ * @var integer
+ */
+ public $page;
/**
- * Per-page value
- * @var integer
- */
- private $perpage;
+ * Per-page value
+ * @var integer
+ */
+ public $perpage;
/**
- * Number of page links
- * @var integer
- */
- private $pagelinks;
+ * Number of page links
+ * @var integer
+ */
+ protected $pagelinks;
/**
- * Total number of results
- * @var integer
- */
- private $total;
+ * Total number of results
+ * @var integer
+ */
+ protected $total;
/**
- * Total number of pages
- * @var integer
- */
- private $pagecount;
+ * Total number of pages
+ * @var integer
+ */
+ protected $pagecount;
/**
- * Name of page variable
- * @var array
- */
- private $pagevar = 'p';
+ * Maximum number of per-page results
+ * @var integer
+ */
+ protected $maxperpage = 100;
/**
- * Name of per-page variable
- * @var integer
- */
- private $perpagevar = 'pp';
+ * Default number of per-page results
+ * @var integer
+ */
+ protected $defaultperpage = 20;
/**
- * Maximum number of per-page results
- * @var integer
- */
- private $maxperpage = 100;
+ * 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);
/**
- * Default number of per-page results
- * @var integer
- */
- private $defaultperpage = 20;
+ * 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);
/**
- * The processing callback public function for individual pagenav bits
- * @var string
- */
- private $bitprocessor = ':undefined:';
+ * Set the Pagination->perpage and Pagination->page variables
+ */
+ protected abstract function _setVariables();
/**
- * The processing callback public function for the entire pagenav system
- * @var string
- */
- private $pagenavprocessor = ':undefined:';
-
- // ###################################################################
- /**
- * 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)
+ * Constructor
+ */
+ public function __construct()
{
- $this->pagenavprocessor = $callback;
+ if (!BSApp::$input instanceof BSInput)
+ {
+ throw new Exception('BSApp::$input is not an instance of BSInput');
+ }
}
- // ###################################################################
/**
- * Returns the current page number
- *
- * @return integer Current page
- */
+ * Returns the current page number
+ *
+ * @return integer Current page
+ */
public function getPage()
{
return $this->page;
}
- // ###################################################################
/**
- * Returns the current perpage value
- *
- * @return integer Current perpage
- */
+ * Returns the current perpage value
+ *
+ * @return integer Current perpage
+ */
public function getPerPage()
{
return $this->perpage;
}
- // ###################################################################
/**
- * Sets total
- *
- * @param integer Total number
- */
+ * Sets total
+ *
+ * @param integer Total number
+ */
public function setTotal($total)
{
$this->total = $total;
}
- // ###################################################################
/**
- * Returns the number of pages to be in the navigator
- *
- * @param integer Number of pages
- */
+ * Returns the number of pages to be in the navigator
+ *
+ * @param integer Number of pages
+ */
public function getPageCount()
{
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
- * prepares all of the data through verification
- */
+ * Takes all of the information from the set() functions and then
+ * prepares all of the data through verification
+ */
public function processIncomingData()
{
- $input = BSRegister::GetType('Input');
- if ($input == null)
- {
- BSRegister::Debug('ISSO/Input not loaded, so manually doing so');
- $input = BSRegister::LoadModule('Input');
- }
-
- $this->page = $input->inputClean($this->pagevar, TYPE_INT);
- $this->perpage = $input->inputClean($this->perpagevar, TYPE_INT);
- $this->pagelinks = $input->clean($this->pagelinks, 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)
{
$this->perpage = $this->maxperpage;
}
- $this->perpage = $input->clean($this->perpage, TYPE_INT);
+ $this->perpage = BSApp::$input->clean($this->perpage, TYPE_INT);
}
- // ###################################################################
/**
- * Takes the variables and splits up the pages
- */
+ * Takes the variables and splits up the pages
+ */
public function splitPages()
{
$this->pagecount = ceil($this->total / $this->perpage);
}
}
- // ###################################################################
/**
- * Returns the lower limit of the pages
- *
- * @param integer Page number
- *
- * @return integer Lower result limit
- */
+ * Returns the lower limit of the pages
+ *
+ * @param integer Page number
+ *
+ * @return integer Lower result limit
+ */
public function fetchLimit($page = null)
{
if ($page === null)
}
}
- // ###################################################################
/**
- * Constructs the page navigator
- *
- * @param string Base link path
- * @param bool Add a ? or a & to the path so it's link-friendly
- *
- * @return string Generated HTML page navigator
- */
+ * Constructs the page navigator
+ *
+ * @param string Base link path
+ * @param bool Add a ? or a & to the path so it's link-friendly
+ *
+ * @return string Generated HTML page navigator
+ */
public function constructPageNav($baselink, $addParam = true)
{
- global $bugsys;
-
// handle base link
if ($addParam)
{
{
$baselink .= '?';
}
- else if (!preg_match('#\?$#', $baselink) AND !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);
}
}
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
?>
\ No newline at end of file