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; } }