/** * Get HTML wrapper for a prev/next page link. * * @param string $url * @param int $page * @param string|null $rel * @return string */ protected function getPrevNextPageLinkWrapper($url, $page, $rel = null) { if ($page == $this->paginator->currentPage()) { return $this->getActivePageWrapper($page); } return $this->getAvailablePrevNextPageWrapper($url, $page, $rel); }
/** * @return array */ protected function getLinks() { $links = [$this->renderPreviousButton()]; if (is_array($this->window['first'])) { foreach ($this->window['first'] as $page => $url) { if ($this->paginator->currentPage() == $page) { $links[] = $this->getActivePageWrapper((string) $page, $url); continue; } $links[] = $this->getPageWrapper((string) $page, $url); } } if (is_array($this->window['slider'])) { $links[] = $this->getDisabledPageWrapper('...'); foreach ($this->window['slider'] as $page => $url) { if ($this->paginator->currentPage() == $page) { $links[] = $this->getActivePageWrapper((string) $page, $url); continue; } $links[] = $this->getPageWrapper((string) $page, $url); } } if (is_array($this->window['last'])) { $links[] = $this->getDisabledPageWrapper('...'); foreach ($this->window['last'] as $page => $url) { if ($this->paginator->currentPage() == $page) { $links[] = $this->getActivePageWrapper((string) $page, $url); continue; } $links[] = $this->getPageWrapper((string) $page, $url); } } $links[] = $this->renderNextButton(); return $links; }
/** * @param Paginator $paginator * @return array */ private static function createPaginationMeta(Paginator $paginator) { $meta = ['page' => $paginator->currentPage(), 'per_page' => $paginator->perPage(), 'count' => count($paginator->items())]; if ($paginator instanceof LengthAwarePaginator) { $meta['total'] = $paginator->total(); $meta['pages'] = $paginator->lastPage() ?: 1; } return $meta; }
/** * Get the next page pagination element. * * @return string */ protected function getNextButton() { // If the current page is greater than or equal to the last page, it means we // can't go any further into the pages, as we're already on this last page // that is available, so we will make it the "next" link style disabled. if (!$this->paginator->hasMorePages()) { return $this->getDisabledTextWrapper($this->getNextButtonText()); } $url = $this->paginator->url($this->paginator->currentPage() + 1); return $this->getPageLinkWrapper($url, $this->getNextButtonText()); }
/** * Get the current page from the paginator. * * @return int */ protected function currentPage() { return $this->paginator->currentPage(); }
/** * Respond with a pagination response. * * @param \Illuminate\Pagination\Paginator $paginator * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\JsonResponse */ protected function paginator(Paginator $paginator, Request $request) { foreach ($request->query as $key => $value) { if ($key != 'page') { $paginator->addQuery($key, $value); } } $pagination = ['pagination' => ['total' => (int) $paginator->total(), 'count' => count($paginator->items()), 'per_page' => (int) $paginator->perPage(), 'current_page' => (int) $paginator->currentPage(), 'total_pages' => (int) $paginator->lastPage(), 'links' => ['next_page' => $paginator->nextPageUrl(), 'previous_page' => $paginator->previousPageUrl()]]]; $items = $paginator->getCollection(); if ($sortBy = $request->get('sort')) { $direction = $request->has('order') && $request->get('order') == 'desc'; $items = $items->sortBy($sortBy, SORT_REGULAR, $direction); } return $this->setMetaData($pagination)->setData(AutoPresenter::decorate($items->values()))->respond(); }
/** * Respond with a pagination response. * * @param \Illuminate\Pagination\Paginator $paginator * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\JsonResponse */ protected function paginator(Paginator $paginator, Request $request) { foreach ($request->query as $key => $value) { if ($key != 'page') { $paginator->addQuery($key, $value); } } $pagination = ['pagination' => ['total' => $paginator->total(), 'count' => count($paginator->items()), 'per_page' => $paginator->perPage(), 'current_page' => $paginator->currentPage(), 'total_pages' => $paginator->lastPage(), 'links' => ['next_page' => $paginator->nextPageUrl(), 'previous_page' => $paginator->previousPageUrl()]]]; return $this->setMetaData($pagination)->setData(AutoPresenter::decorate($paginator->getCollection()))->respond(); }
/** * Get the current page. * * @return int */ public function getCurrentPage() { return $this->paginator->currentPage(); }
/** * @param Paginator $items * @param $data * * @return mixed */ public function respondWithPagination(Paginator $items, $data) { $data = array_merge($data, ['paginate' => ['total_count' => $items->total(), 'total_page' => ceil($items->total() / $items->perPage()), 'current_page' => $items->currentPage(), 'limit' => $items->perPage()]]); return $this->respond($data); }