public function getPageCount() { $pageSize = $this->getPageSize(); if ($pageSize < 1) { return $this->totalCount > 0 ? 1 : 0; } else { $totalCount = $this->totalCount < 0 ? 0 : (int) $this->totalCount; return (int) (($totalCount + $pageSize - 1) / $pageSize); } }
/** * Adds HTTP headers about the pagination to the response. * @param Pagination $pagination */ protected function addPaginationHeaders($pagination) { $links = []; foreach ($pagination->getLinks(true) as $rel => $url) { $links[] = "<{$url}>; rel={$rel}"; } $this->response->getHeaders()->set($this->totalCountHeader, $pagination->totalCount)->set($this->pageCountHeader, $pagination->getPageCount())->set($this->currentPageHeader, $pagination->getPage() + 1)->set($this->perPageHeader, $pagination->pageSize)->set('Link', implode(', ', $links)); }