| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace Meramo\Mrmbepages\Paginator;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
- class Paginator
- {
- /**
- * @var array $data
- */
- protected $data;
- /**
- * @var int $totalRecords
- */
- protected $totalRecords;
- /**
- * @var int $itemsPerPage
- */
- protected $itemsPerPage;
- /**
- * @var int @offSet
- */
- protected $offSet;
- /**
- * @var int $totalPages
- */
- protected $totalPages;
- /**
- * @var int $currentPage
- */
- protected $currentPage;
- /**
- * @var $nextPage
- */
- protected $nextPage;
- /**
- * @var $previousPage
- */
- protected $previousPage;
-
- /**
- * @var $paginatedData
- */
- protected $paginatedData;
- public function __construct(){}
- public function setData(array $data) {
- $this->data = $data;
- }
- public function getData()
- {
- return $this->data;
- }
- public function getTotalRecords(): int
- {
- $this->totalRecords = count($this->getData());
-
- return $this->totalRecords;
- }
- public function setItemsPerPage(int $itemsPerPage)
- {
- $this->itemsPerPage = $itemsPerPage;
- }
- public function getItemsPerPage(): int
- {
- return $this->itemsPerPage;
- }
- public function getTotalPages()
- {
- $this->totalPages = ceil($this->totalRecords / $this->itemsPerPage);
- return $this->totalPages;
- }
- public function getCurrentPage(): int
- {
- if($this->currentPage < 1) $this->currentPage = 1;
- if($this->currentPage > $this->totalPages) $this->currentPage = $this->totalPages;
- return (int) $this->currentPage;
- }
- public function setCurrentPage($currentPage)
- {
- $this->currentPage = $currentPage;
- }
- public function getNextPage():int
- {
- if($this->getCurrentPage() < $this->getTotalPages()) {
- $this->nextPage = (int) ($this->getCurrentPage() + 1);
- } else $this->nextPage = $this->getTotalPages();
- return $this->nextPage;
- }
- public function getPreviousPage()
- {
- if($this->currentPage > 1) {
- $this->previousPage = (int) $this->currentPage - 1;
- }
- return $this->previousPage;
- }
- public function getOffSet(): int
- {
- return $this->offSet = ((int) $this->currentPage -1) * $this->pageSize;
- }
- public function getPaginatedData()
- {
- $offset = ((int) $this->getCurrentPage() -1) * $this->itemsPerPage;
- $this->paginatedData = array_slice($this->data, $offset, $this->itemsPerPage);
- return $this->paginatedData;
- }
-
- }
|