public function generate($strSeparator = ' ')
{
if ($this->intRowsPerPage < 1) {
return '';
}
$blnQuery = false;
list($this->strUrl) = explode('?', \Environment::get('request'), 2);
// Prepare the URL
foreach (preg_split('/&(amp;)?/', \Environment::get('queryString'), -1, PREG_SPLIT_NO_EMPTY) as $fragment) {
if (strpos($fragment, $this->strParameter . '=') === false) {
$this->strUrl .= (!$blnQuery ? '?' : '&') . $fragment;
$blnQuery = true;
}
}
$this->strVarConnector = $blnQuery ? '&' : '?';
$this->intTotalPages = ceil($this->intRows / $this->intRowsPerPage);
// Return if there is only one page
if ($this->intTotalPages < 2 || $this->intRows < 1) {
return '';
}
if ($this->intPage > $this->intTotalPages) {
$this->intPage = $this->intTotalPages;
}
$objTemplate = $this->objTemplate;
$objTemplate->hasFirst = $this->hasFirst();
$objTemplate->hasPrevious = $this->hasPrevious();
$objTemplate->hasNext = $this->hasNext();
$objTemplate->hasLast = $this->hasLast();
// Deprecated since Contao 4.0, to be removed in Contao 5.0
$objTemplate->items = $this->getItemsAsString($strSeparator);
$objTemplate->pages = $this->getItemsAsArray();
$objTemplate->total = sprintf($this->lblTotal, $this->intPage, $this->intTotalPages);
$objTemplate->first = array('link' => $this->lblFirst, 'href' => $this->linkToPage(1), 'title' => sprintf(\StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), 1));
$objTemplate->previous = array('link' => $this->lblPrevious, 'href' => $this->linkToPage($this->intPage - 1), 'title' => sprintf(\StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), $this->intPage - 1));
$objTemplate->next = array('link' => $this->lblNext, 'href' => $this->linkToPage($this->intPage + 1), 'title' => sprintf(\StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), $this->intPage + 1));
$objTemplate->last = array('link' => $this->lblLast, 'href' => $this->linkToPage($this->intTotalPages), 'title' => sprintf(\StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), $this->intTotalPages));
$objTemplate->class = 'pagination-' . $this->strParameter;
// Adding rel="prev" and rel="next" links is not possible
// anymore with unique variable names (see #3515 and #4141)
return $objTemplate->parse();
}