/** * Get the next page number. * * @param \Illuminate\Contracts\Pagination\Paginator $paginator * * @return string|null */ public function nextPage(Paginator $paginator) { if (!$paginator->hasMorePages()) { return; } return $this->currentPage() + 1; }
/** * Get the next page number * * @param \Illuminate\Contracts\Pagination\Paginator $paginator * @return string|null */ public function nextPage(Paginator $paginator) { if (!$paginator->hasMorePages()) { return null; } return $this->router->getCurrentRoute()->parameter('page', 1) + 1; }
/** * @param Paginator $value * * @return array */ protected function serializeEloquentPaginatedResource(Paginator $value) { $items = []; foreach ($value->items() as $v) { $items[] = $this->serializeObject($v); } return [self::MAP_TYPE => 'array', self::SCALAR_VALUE => $items]; }
protected function appendPaginationLinks(Paginator $paginator, Request $request) { if ($request->has('count')) { $paginator->appends(['count' => $request->get('count')]); } if ($request->has('include')) { $paginator->appends(['include' => $request->get('include')]); } }
/** * 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; }
/** * 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()); }
/** * @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; }
/** * Bind a paginator to a transformer and start building a response. * * @param \Illuminate\Contracts\Pagination\Paginator $paginator * @param object $transformer * @param array $parameters * @param \Closure $after * * @return \Dingo\Api\Http\Response */ public function paginator(Paginator $paginator, $transformer, array $parameters = [], Closure $after = null) { if ($paginator->isEmpty()) { $class = get_class($paginator); } else { $class = get_class($paginator->first()); } $binding = $this->transformer->register($class, $transformer, $parameters, $after); return new Response($paginator, 200, [], $binding); }
/** * 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(); }
/** * 生成特定页面URL * * @return string */ protected function getUrl($page) { return $this->paginator->url($page); }
/** * Render a table showing jobs. * * @param Paginator $jobs * * @return mixed */ protected function renderJobsTable(Paginator $jobs) { return Std::firstBias(count($jobs->items()) > 0, function () use($jobs) { return new SimpleTable(['ID', 'Task', 'State', 'Runs', 'Created At', 'Duration'], Std::map(function (Job $job) { return [$job->id, $job->state, $job->task, $job->attempts, $job->created_at->toDayDateTimeString(), $job->getExecutionTime()]; }, $jobs->items())); }, function () { return new CardBlock(['class' => 'card-block text-center'], [new Paragraph([], [new Italic(['class' => 'fa fa-4x fa-search text-light'])]), 'No jobs found matching the specified criteria.']); }); }
/** * Parse a collection of objects. * * @param Model|array|Paginator|Collection $result * @return mixed * @throws NotFoundError */ public function parseResult($result) { $this->logSqlQueries(); if ($result == null) { throw new NotFoundError($this->getMessage('not_found')); } if ($this->presenter instanceof PresenterInterface) { if ($result instanceof Collection || $result instanceof LengthAwarePaginator) { $result->each(function ($model) { if ($model instanceof Presentable) { $model->setPresenter($this->presenter); } return $model; }); } elseif ($result instanceof Presentable) { $result = $result->setPresenter($this->presenter); } if (!$this->skipPresenter) { return $this->presenter->present($result); } } return $result; }
/** * Get the lastItem from the paginator. * * @return int */ protected function currentPageCount() { return $this->paginator->count(); }
/** * 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 url for the given page. * * @param int $page * * @return string */ public function getUrl($page) { return $this->paginator->url($page); }
/** * @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); }
/** * Get the last page from the paginator. * * @return int */ protected function lastPage() { return $this->paginator->lastPage(); }
/** * Render the object into a string. * * @return mixed */ public function render() { return Std::firstBias($this->paginator->hasPages(), function () { return new CardBlock(['class' => 'card-block text-center'], new BootstrapFourPaginatorPresenter($this->paginator)); }, ''); }