‪TYPO3CMS  ‪main
SimplePagination.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 {
25  protected ‪$paginator;
26 
28  {
29  $this->paginator = ‪$paginator;
30  }
31 
32  public function ‪getPreviousPageNumber(): ?int
33  {
34  $previousPage = $this->paginator->getCurrentPageNumber() - 1;
35 
36  if ($previousPage > $this->paginator->getNumberOfPages()) {
37  return null;
38  }
39 
40  return $previousPage >= $this->‪getFirstPageNumber()
41  ? $previousPage
42  : null
43  ;
44  }
45 
46  public function ‪getNextPageNumber(): ?int
47  {
48  $nextPage = $this->paginator->getCurrentPageNumber() + 1;
49 
50  return $nextPage <= $this->paginator->getNumberOfPages()
51  ? $nextPage
52  : null
53  ;
54  }
55 
56  public function ‪getFirstPageNumber(): int
57  {
58  return 1;
59  }
60 
61  public function ‪getLastPageNumber(): int
62  {
63  return $this->paginator->getNumberOfPages();
64  }
65 
66  public function ‪getStartRecordNumber(): int
67  {
68  if ($this->paginator->getCurrentPageNumber() > $this->paginator->getNumberOfPages()) {
69  return 0;
70  }
71 
72  return $this->paginator->getKeyOfFirstPaginatedItem() + 1;
73  }
74 
75  public function ‪getEndRecordNumber(): int
76  {
77  if ($this->paginator->getCurrentPageNumber() > $this->paginator->getNumberOfPages()) {
78  return 0;
79  }
80 
81  return $this->paginator->getKeyOfLastPaginatedItem() + 1;
82  }
83 
87  public function ‪getAllPageNumbers(): array
88  {
89  return range($this->‪getFirstPageNumber(), $this->‪getLastPageNumber());
90  }
91 }
‪TYPO3\CMS\Core\Pagination\PaginationInterface
Definition: PaginationInterface.php:27
‪TYPO3\CMS\Core\Pagination\SimplePagination\getPreviousPageNumber
‪getPreviousPageNumber()
Definition: SimplePagination.php:31
‪TYPO3\CMS\Core\Pagination\SimplePagination\getNextPageNumber
‪getNextPageNumber()
Definition: SimplePagination.php:45
‪TYPO3\CMS\Core\Pagination
Definition: AbstractPaginator.php:18
‪TYPO3\CMS\Core\Pagination\SimplePagination
Definition: SimplePagination.php:21
‪TYPO3\CMS\Core\Pagination\SimplePagination\getFirstPageNumber
‪getFirstPageNumber()
Definition: SimplePagination.php:55
‪TYPO3\CMS\Core\Pagination\SimplePagination\getEndRecordNumber
‪getEndRecordNumber()
Definition: SimplePagination.php:74
‪TYPO3\CMS\Core\Pagination\SimplePagination\$paginator
‪PaginatorInterface $paginator
Definition: SimplePagination.php:24
‪TYPO3\CMS\Core\Pagination\PaginatorInterface
Definition: PaginatorInterface.php:25
‪TYPO3\CMS\Core\Pagination\SimplePagination\getStartRecordNumber
‪getStartRecordNumber()
Definition: SimplePagination.php:65
‪TYPO3\CMS\Core\Pagination\SimplePagination\getAllPageNumbers
‪int[] getAllPageNumbers()
Definition: SimplePagination.php:86
‪TYPO3\CMS\Core\Pagination\SimplePagination\getLastPageNumber
‪getLastPageNumber()
Definition: SimplePagination.php:60
‪TYPO3\CMS\Core\Pagination\SimplePagination\__construct
‪__construct(PaginatorInterface $paginator)
Definition: SimplePagination.php:26