public
__construct
(mixed $total, mixed $limitstart, mixed $limit, mixed $prefix = '', \Joomla\CMS\Application\CMSApplication $app = null)
/**
* Constructor.
*
* @param integer $total The total number of items.
* @param integer $limitstart The offset of the item to start at.
* @param integer $limit The number of items to display per page.
* @param string $prefix The prefix used for request variables.
* @param CMSApplication $app The application object
*
* @since 1.5
*/
public function __construct($total, $limitstart, $limit, $prefix = '', CMSApplication $app = null)
{
// Value/type checking.
$this->total = (int) $total;
$this->limitstart = (int) max($limitstart, 0);
$this->limit = (int) max($limit, 0);
$this->prefix = $prefix;
$this->app = $app ?: Factory::getApplication();
if ($this->limit > $this->total) {
$this->limitstart = 0;
}
if (!$this->limit) {
$this->limit = $total;
$this->limitstart = 0;
}
/*
* If limitstart is greater than total (i.e. we are asked to display records that don't exist)
* then set limitstart to display the last natural page of results
*/
if ($this->limitstart > $this->total - $this->limit) {
$this->limitstart = max(0, (int) (ceil($this->total / $this->limit) - 1) * $this->limit);
}
// Set the total pages and current page values.
if ($this->limit > 0) {
$this->pagesTotal = (int) ceil($this->total / $this->limit);
$this->pagesCurrent = (int) ceil(($this->limitstart + 1) / $this->limit);
}
// Set the pagination iteration loop values.
$displayedPages = 10;
$this->pagesStart = $this->pagesCurrent - $displayedPages / 2;
if ($this->pagesStart < 1) {
$this->pagesStart = 1;
}
if ($this->pagesStart + $displayedPages > $this->pagesTotal) {
$this->pagesStop = $this->pagesTotal;
if ($this->pagesTotal < $displayedPages) {
$this->pagesStart = 1;
} else {
$this->pagesStart = $this->pagesTotal - $displayedPages + 1;
}
} else {
$this->pagesStop = $this->pagesStart + $displayedPages - 1;
}
// If we are viewing all records set the view all flag to true.
if ($limit === 0) {
$this->viewall = true;
}
}