Commit 7149d823 authored by Tino Goratsch's avatar Tino Goratsch

changed the defaults of the pagination, so that it fits into one line even on smartphones

parent b56e0387
......@@ -48,11 +48,11 @@ class Pagination
/**
* @var int
*/
private $showPreviousNext = 2;
private $showPreviousNext = 1;
/**
* @var int
*/
private $pagesToDisplay = 7;
private $pagesToDisplay = 3;
/**
* @var int
*/
......@@ -129,6 +129,27 @@ class Pagination
return $this;
}
/**
* @return int
*/
private function getPagesToDisplay(): int
{
$pagesToDisplay = $this->pagesToDisplay;
$map = [
$this->canShowNextPageLink(),
$this->canShowPreviousPageLink(),
];
foreach ($map as $result) {
if (!$result) {
$pagesToDisplay++;
}
}
return $pagesToDisplay;
}
/**
* @param int $showFirstLast
* @return $this
......@@ -176,20 +197,20 @@ class Pagination
$this->setMetaStatements();
$range = $this->calculateRange();
$this->showFirstPageLink($link, $range);
$this->showPreviousPageLink($link);
$this->addFirstPageLink($link, $range['start']);
$this->addPreviousPageLink($link);
for ($i = (int)$range['start']; $i <= $range['end']; ++$i) {
$this->pagination[] = $this->buildPageNumber(
$i,
$link . ($i > 1 ? 'page_' . $i . '/' : '') . $this->urlFragment,
for ($pageNumber = (int)$range['start']; $pageNumber <= $range['end']; ++$pageNumber) {
$this->addPageNumber(
$pageNumber,
$link . ($pageNumber > 1 ? 'page_' . $pageNumber . '/' : '') . $this->urlFragment,
'',
$this->currentPage === $i
$this->currentPage === $pageNumber
);
}
$this->showNextPageLink($link);
$this->showLastPageLink($link, $range);
$this->addNextPageLink($link);
$this->addLastPageLink($link, $range['end']);
}
return $this->pagination;
......@@ -213,20 +234,22 @@ class Pagination
{
$rangeStart = 1;
$rangeEnd = $this->totalPages;
if ($this->totalPages > $this->pagesToDisplay) {
$center = floor($this->pagesToDisplay / 2);
$pagesToDisplay = $this->getPagesToDisplay();
if ($this->totalPages > $pagesToDisplay) {
$center = floor($pagesToDisplay / 2);
// Beginn der anzuzeigenden Seitenzahlen
if ($this->currentPage - $center > 0) {
$rangeStart = $this->currentPage - $center;
}
// Ende der anzuzeigenden Seitenzahlen
if ($rangeStart + $this->pagesToDisplay - 1 <= $this->totalPages) {
$rangeEnd = $rangeStart + $this->pagesToDisplay - 1;
if ($rangeStart + $pagesToDisplay - 1 <= $this->totalPages) {
$rangeEnd = $rangeStart + $pagesToDisplay - 1;
}
// Anzuzeigende Seiten immer auf dem Wert von $this->pagesToDisplay halten
if ($rangeEnd - $rangeStart < $this->pagesToDisplay && $rangeEnd - $this->pagesToDisplay > 0) {
$rangeStart = $rangeEnd - $this->pagesToDisplay + 1;
// Anzuzeigende Seiten immer auf dem Wert von $pagesToDisplay halten
if ($rangeEnd - $rangeStart < $pagesToDisplay && $rangeEnd - $pagesToDisplay > 0) {
$rangeStart = $rangeEnd - $pagesToDisplay + 1;
}
}
......@@ -238,12 +261,12 @@ class Pagination
/**
* @param string $link
* @param array $range
* @param integer $rangeStart
*/
private function showFirstPageLink($link, array $range)
private function addFirstPageLink($link, $rangeStart)
{
if ($this->totalPages > $this->showFirstLast && $range['start'] > 1) {
$this->pagination[] = $this->buildPageNumber(
if ($this->totalPages > $this->showFirstLast && $rangeStart > 1) {
$this->addPageNumber(
'&laquo;',
$link . $this->urlFragment,
$this->translator->t('system', 'first_page')
......@@ -252,10 +275,24 @@ class Pagination
}
/**
* @param int $pageNumber
* @param int $pageNumber
* @param string $uri
* @param string $title
* @param bool $selected
* @param bool $selected
* @return $this
*/
private function addPageNumber($pageNumber, $uri, $title = '', $selected = false)
{
$this->pagination[] = $this->buildPageNumber($pageNumber, $uri, $title, $selected);
return $this;
}
/**
* @param int $pageNumber
* @param string $uri
* @param string $title
* @param bool $selected
*
* @return array
*/
......@@ -272,10 +309,10 @@ class Pagination
/**
* @param string $link
*/
private function showPreviousPageLink($link)
private function addPreviousPageLink($link)
{
if ($this->totalPages > $this->showPreviousNext && $this->currentPage !== 1) {
$this->pagination[] = $this->buildPageNumber(
if ($this->canShowPreviousPageLink()) {
$this->addPageNumber(
'&lsaquo;',
$link . ($this->currentPage - 1 > 1 ? 'page_' . ($this->currentPage - 1) . '/' : '') . $this->urlFragment,
$this->translator->t('system', 'previous_page')
......@@ -283,13 +320,21 @@ class Pagination
}
}
/**
* @return bool
*/
private function canShowPreviousPageLink(): bool
{
return $this->totalPages > $this->showPreviousNext && $this->currentPage !== 1;
}
/**
* @param string $link
*/
private function showNextPageLink($link)
private function addNextPageLink($link)
{
if ($this->totalPages > $this->showPreviousNext && $this->currentPage !== $this->totalPages) {
$this->pagination[] = $this->buildPageNumber(
if ($this->canShowNextPageLink()) {
$this->addPageNumber(
'&rsaquo;',
$link . 'page_' . ($this->currentPage + 1) . '/' . $this->urlFragment,
$this->translator->t('system', 'next_page')
......@@ -297,14 +342,22 @@ class Pagination
}
}
/**
* @return bool
*/
private function canShowNextPageLink(): bool
{
return $this->totalPages > $this->showPreviousNext && $this->currentPage !== $this->totalPages;
}
/**
* @param string $link
* @param array $range
* @param integer $rangeEnd
*/
private function showLastPageLink($link, array $range)
private function addLastPageLink($link, $rangeEnd)
{
if ($this->totalPages > $this->showFirstLast && $this->totalPages !== $range['end']) {
$this->pagination[] = $this->buildPageNumber(
if ($this->totalPages > $this->showFirstLast && $this->totalPages !== $rangeEnd) {
$this->addPageNumber(
'&raquo;',
$link . 'page_' . $this->totalPages . '/' . $this->urlFragment,
$this->translator->t('system', 'last_page')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment