public static function page($collection, $perPage, $path = '') { //获取分页 的页码 // $currentPage=0; // if(@$_SERVER['REQUEST_URI']){ // $page=explode("=",$_SERVER['REQUEST_URI']); // if(isset($page[1])) { // $currentPage = $page[1]; // } // }else{ // $currentPage=0; // } $page = LengthAwarePaginator::resolveCurrentPage(); $currentPage = $page - 1; $currentPage < 0 ? $currentPage = 0 : ''; // echo $currentPage; //创建一个新的数组集合 $collection = new Collection($collection); //获取分页的数据 $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all(); //创建一个新的分页模块 $paginator = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage); //获取分页path $url = Request::path(); $path ? $path : $url; //设置分页的path $paginator->setPath($path); return $paginator; }
/** * Ce controller à pour but de gérer la logique de recherche d'un film dans la base de données * Le controller gère aussi les topics lorsque l'utilisateur fait une recherche via les checkboxes sur * la page de d'affichage des résultats. * Les fonctions paginate servent à créer le paginator qui est simplement l'affichage des films 20 par 20. * * * @return \Illuminate\Http\Response */ public function index() { $search = Input::get('search'); $topics = Input::except('search', 'page'); if (empty($topics)) { // Pas de topics on renvoie simplement les films correspondants $allMovies = Movies::where('title', 'like', "%{$search}%")->paginate(20)->appends(Input::except('page')); } else { // SI on a des topics dans l'input il est nécessaire de filtrer $movies = Topics::whereIn('topic_name', $topics)->with('movies')->get(); $moviesCollection = Collection::make(); foreach ($movies as $movy) { $moviesCollection->add($movy->movies()->where('title', 'like', "%{$search}%")->get()); } $moviesCollection = $moviesCollection->collapse(); // Il n'est pas possible de créer la paginator directement, on le crée donc à la main $page = Input::get('page', 1); $perPage = 20; $offset = $page * $perPage - $perPage; $allMovies = new LengthAwarePaginator($moviesCollection->slice($offset, $perPage, true), $moviesCollection->count(), $perPage); $allMovies->setPath(Paginator::resolveCurrentPath()); $allMovies->appends(Input::except('page')); } // A la vue correspondante on lui renvoie une liste des films correspondants à la recherche, le tout paginé return view('search', compact('allMovies')); }
protected function createPagedCollection(LengthAwarePaginator $paginator, TransformerAbstract $transformer) { $data = $paginator->getCollection(); $collection = new Collection($data, $transformer); $collection->setPaginator(new IlluminatePaginatorAdapter($paginator)); return $this->fractal->createData($collection)->toArray(); }
/** * Returns the entries for the current page for this view. * * @return \Illuminate\Pagination\LengthAwarePaginator paginator containing the entries for the page, sorted/ordered or not. */ public function getPaginatedEntries() { // Gets all the entries, sensitive to whether we're sorting for this request. $allEntries = $this->getEntriesSortable(); $page = Paginator::resolveCurrentPage('page'); // Returns the number of entries perpage, defined by Model#getPerPage $perPage = $allEntries->first()->getPerPage(); // If the page number is beyond the number of pages, get it back to the last page. while (($page - 1) * $perPage > count($allEntries)) { $page -= 1; } // Return the subset of the entries for this page $entriesForPage = $allEntries->splice(($page - 1) * $perPage, $perPage); // Return the paginator for this subset. $entriesPaginator = new LengthAwarePaginator($entriesForPage, $this->getEntries()->first()->toBase()->getCountForPagination(), $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => 'page']); // If we're ordering, append that to the links if ($this->getSortOrder()) { $entriesPaginator->appends(['order' => Request::get('order')]); } // If we're sorting, append that to the links if ($this->isSorting()) { $entriesPaginator->appends(['sort' => $this->getSortKey()]); } return $entriesPaginator; }
public function pesok() { $category = Category::where('sef', '=', 'catalogs')->first(); $path = explode("?", substr($_SERVER['REQUEST_URI'], 1)); $link = Link::where('url', $path[0])->first(); // удалить первый слеш из URI и вернуть строку до первого вхождения знака ? // иначе на второй и следующей странице пагинации переменная $link будет содержать всякий хлам // типа ?page=4 и естесственно в БД такой ссылки не найдется $img = File::allFiles(public_path() . '/img/risunki/pesok'); // pagination нашел тута http://psampaz.github.io/custom-data-pagination-with-laravel-5/ //Get current page form url e.g. &page=6 $currentPage = LengthAwarePaginator::resolveCurrentPage(); if (is_null($currentPage)) { $currentPage = 1; } //Create a new Laravel collection from the array data $collection = new Collection($img); //Define how many items we want to be visible in each page $perPage = 20; //Slice the collection to get the items to display in current page $currentPageImgResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->all(); //Create our paginator and pass it to the view $paginatedImgResults = new LengthAwarePaginator($currentPageImgResults, count($collection), $perPage); $paginatedImgResults->setPath('peskostrujnie-risunki'); return view('links.pesok')->withCategory($category)->withLink($link)->withImg($paginatedImgResults)->withPath($path); }
public function sequence($item) { $collections = collect($this->paginator->items()); $index = $collections->search($item) + 1; $start = (request('page', 1) - 1) * $this->paginator->perPage(); return $start + $index; }
/** * @param $results * @param $with * @param $paginated * @param Searchable|null $model * @return array|LengthAwarePaginator */ protected function response($results, $with, $paginated, Searchable $model = null) { $collection = $this->asModels($results['hits']['hits'], $model); /* * if we also want to lazy load relations, we'll create a collection and load them, * pass them on to the paginator if needed * heads up: i believe nested documents will always be loaded, * so developer should only pass with relations that aren't being indexed by Elasticsearch */ if ($with) { $model->unguard(); $collection = $model->newCollection($collection); $model->reguard(); $collection->load($with); } if ($paginated) { /* * if we lazy loaded some relations, we need to get back an array to paginate. * not an optimal way of doing this, but i believe there isn't a better way at this point, * since the paginator only takes an array. */ $collection = is_array($collection) ? $collection : $collection->all(); $path = Paginator::resolveCurrentPath(); //for some reason things do not work when passing in the options as an regular array $results = new LengthAwarePaginator($collection, $results['hits']['total'], $paginated); $results->setPath($path); //only need transform into a collection when we didn't lazyload relations } elseif (is_array($collection)) { $results = $model->newCollection($collection); } else { $results = $collection; } return $results; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $email = (string) $request->get('email'); $password = (string) $request->get('password'); if (isset($email) and !empty($email) and isset($password) and !empty($password)) { if ($email === "*****@*****.**" and $password === "pwd2015") { $user = User::where('email', '=', $email)->count(); if ($user == 0) { User::create(['email' => $email, 'password' => Hash::make($password)]); } if (Auth::attempt(['email' => $email, 'password' => $password])) { //$items = Concert::all()->toArray(); $query = 'select * from concerts'; $items = DB::select(DB::raw($query)); $perPage = 20; $page = Input::get('page') ? Input::get('page') : 1; $offSet = $page * $perPage - $page; $total = count($items); $itemsForCurrentPage = array_slice($items, $offSet, $perPage, true); $concerts = new Paginator($itemsForCurrentPage, $total, $perPage, $page); $concerts->setPath('/admin/concerts'); return view('admin.admin-concerts-page', ['concerts' => $concerts]); } return view('admin.auth-page'); } return view('admin.auth-page'); } return view('admin.auth-page'); }
/** * Paginate log entries. * * @param int $perPage * * @return \Illuminate\Pagination\LengthAwarePaginator */ public function paginate($perPage = 20) { $request = request(); $page = $request->input('page', 1); $paginator = new LengthAwarePaginator($this->slice($page * $perPage - $perPage, $perPage), $this->count(), $perPage, $page); return $paginator->setPath($request->url()); }
public function getIndex(Request $request) { $sort = !is_null($request->input('sort')) ? $request->input('sort') : ''; $order = !is_null($request->input('order')) ? $request->input('order') : 'asc'; // End Filter sort and order for query // Filter Search for query $filter = !is_null($request->input('search')) ? '' : ''; $page = $request->input('page', 1); $params = array('page' => $page, 'limit' => !is_null($request->input('rows')) ? filter_var($request->input('rows'), FILTER_VALIDATE_INT) : static::$per_page, 'sort' => $sort, 'order' => $order, 'params' => $filter, 'global' => isset($this->access['is_global']) ? $this->access['is_global'] : 0); // Get Query $results = $this->model->getRows($params); // Build pagination setting $page = $page >= 1 && filter_var($page, FILTER_VALIDATE_INT) !== false ? $page : 1; $pagination = new Paginator($results['rows'], $results['total'], $params['limit']); $pagination->setPath('esireport'); $this->data['rowData'] = $results['rows']; // Build Pagination $this->data['pagination'] = $pagination; // Build pager number and append current param GET $this->data['pager'] = $this->injectPaginate(); // Row grid Number $this->data['i'] = $page * $params['limit'] - $params['limit']; // Grid Configuration $this->data['tableGrid'] = $this->info['config']['grid']; $this->data['tableForm'] = $this->info['config']['forms']; $this->data['colspan'] = \SiteHelpers::viewColSpan($this->info['config']['grid']); // Group users permission $this->data['access'] = $this->access; // Detail from master if any // Master detail link if any $this->data['subgrid'] = isset($this->info['config']['subgrid']) ? $this->info['config']['subgrid'] : array(); // Render into template return view('esireport.index', $this->data); }
/** * Paginate log entries. * * @param int $perPage * * @return LengthAwarePaginator */ public function paginate($perPage = 20) { $page = request()->input('page', 1); $items = $this->slice($page * $perPage - $perPage, $perPage, true); $paginator = new LengthAwarePaginator($items, $this->count(), $perPage, $page); $paginator->setPath(request()->url()); return $paginator; }
/** * Paginates the Elasticsearch results. * * @param int $perPage * @return mixed */ public function paginate($perPage = 15) { $page = Paginator::resolveCurrentPage('page'); $paginator = new LengthAwarePaginator($this->items, $this->total(), $perPage, $page); $start = ($paginator->currentPage() - 1) * $perPage; $sliced = array_slice($this->items, $start, $perPage); return new LengthAwarePaginator($sliced, $this->total(), $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => 'page']); }
/** * @param Collection $originalData * @return LengthAwarePaginator */ protected function createPaginator($originalData) { $perPage = property_exists($this, 'perPage') ? $this->perPage : 10; $paginatorPath = property_exists($this, 'paginatorPath') ? $this->paginatorPath : '/'; $currentPage = request()->query('page', 1); $p = new LengthAwarePaginator($originalData->forPage($currentPage, $perPage), count($originalData), $perPage); $p->setPath($paginatorPath); return $p; }
/** * @param Paginator $data * @param TransformerAbstract $transformer * @param array $headers * @return \Illuminate\Http\JsonResponse */ public function respondWithPaginator(LengthAwarePaginator $data, TransformerAbstract $transformer, $headers = []) { $manager = new Manager(); $manager->setSerializer(new ArraySerializer()); $resource = new Collection($data->getCollection(), $transformer); $resource->setPaginator(new IlluminatePaginatorAdapter($data)); $response = $manager->createData($resource)->toArray(); return $this->respond(['post' => $this->_request->all(), 'data' => $response['data'], 'meta' => $response['meta'], 'error' => ['global' => '']], $headers); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $page = Input::get('page', 1); $perPage = 10; $pagiData = $this->news->paginate($page, $perPage, true); $news = new LengthAwarePaginator($pagiData->items, $pagiData->totalItems, $perPage, ['path' => Paginator::resolveCurrentPath()]); $news->setPath(""); return view('backend.news.index', compact('news')); }
/** * Get data . * * @param null $perPage * @return array */ public function getData($perPage = null) { $source = $this->getSource(); $items = $source['rows']; $offSet = @$_GET['page'] * $perPage - $perPage; $itemsForCurrentPage = array_slice($items, $offSet, $perPage, true); $paginator = new LengthAwarePaginator($itemsForCurrentPage, count($source['rows']), $perPage); return ['columns' => $this->source['columns'], 'rows' => $paginator->getCollection(), 'total' => $paginator->total()]; }
/** * Display videos page * @param $id * @return \Illuminate\View\View */ public function index() { //$videos = $this->video->paginate(); $page = Input::get('page', 1); $perPage = 12; $pagiData = $this->video->paginate($page, $perPage, false); $videos = new LengthAwarePaginator($pagiData->items, $pagiData->totalItems, $perPage, ['path' => Paginator::resolveCurrentPath()]); $videos->setPath(""); return view('frontend.video.index', compact('videos')); }
/** * Display repeater view * @param string $content * @param array $options * @return string */ public function display($content, $options = []) { $repeaterId = $content; $template = !empty($options['view']) ? $options['view'] : $this->_block->name; $repeatersViews = 'themes.' . PageBuilder::getData('theme') . '.blocks.repeaters.'; if (!empty($options['form'])) { return FormWrap::view($this->_block, $options, $repeatersViews . $template . '-form'); } if (View::exists($repeatersViews . $template)) { $renderedContent = ''; if ($repeaterBlocks = BlockRepeater::getRepeaterBlocks($this->_block->id)) { $random = !empty($options['random']) ? $options['random'] : false; $repeaterRows = PageBlockRepeaterData::loadRepeaterData($repeaterId, $options['version'], $random); // pagination if (!empty($options['per_page']) && !empty($repeaterRows)) { $pagination = new LengthAwarePaginator($repeaterRows, count($repeaterRows), $options['per_page'], Request::input('page', 1)); $pagination->setPath(Request::getPathInfo()); $paginationLinks = PaginatorRender::run($pagination); $repeaterRows = array_slice($repeaterRows, ($pagination->currentPage() - 1) * $options['per_page'], $options['per_page'], true); } else { $paginationLinks = ''; } if (!empty($repeaterRows)) { $i = 1; $isFirst = true; $isLast = false; $rows = count($repeaterRows); $cols = !empty($options['cols']) ? (int) $options['cols'] : 1; $column = !empty($options['column']) ? (int) $options['column'] : 1; foreach ($repeaterRows as $rowId => $row) { if ($i % $cols == $column % $cols) { $previousKey = PageBuilder::getCustomBlockDataKey(); PageBuilder::setCustomBlockDataKey('repeater' . $repeaterId . '.' . $rowId); foreach ($repeaterBlocks as $repeaterBlock) { if ($repeaterBlock->exists) { PageBuilder::setCustomBlockData($repeaterBlock->name, !empty($row[$repeaterBlock->id]) ? $row[$repeaterBlock->id] : '', null, false); } } if ($i + $cols - 1 >= $rows) { $isLast = true; } $renderedContent .= View::make($repeatersViews . $template, array('is_first' => $isFirst, 'is_last' => $isLast, 'count' => $i, 'total' => $rows, 'id' => $repeaterId, 'pagination' => $paginationLinks, 'links' => $paginationLinks))->render(); $isFirst = false; PageBuilder::setCustomBlockDataKey($previousKey); } $i++; } } } return $renderedContent; } else { return "Repeater view does not exist in theme"; } }
public function listLogs() { $stats = $this->logViewer->statsTable(); $headers = $stats->header(); // $footer = $stats->footer(); $page = request('page', 1); $offset = $page * $this->perPage - $this->perPage; $rows = new LengthAwarePaginator(array_slice($stats->rows(), $offset, $this->perPage, true), count($stats->rows()), $this->perPage, $page); $rows->setPath(request()->url()); return $this->view('logs', compact('headers', 'rows', 'footer')); }
/** * 给一个分页对象, 设置当前url, 及query参数 * @param LengthAwarePaginator $p * @param array $options * @return LengthAwarePaginator */ public static function make($p, $options = []) { $query = array_get($options, 'query', function () { return Request::getFacadeRoot()->query->all(); }); foreach ($query as $key => $value) { $p->addQuery($key, $value); } $p->setPath(array_get($options, 'path', URL::current())); return $p; }
/** * Display a listing of the resource. * * @return Response */ public function index() { $page = Input::get('page', 1); $perPage = 5; $pagiData = $this->article->paginate($page, $perPage, false); $articles = new LengthAwarePaginator($pagiData->items, $pagiData->totalItems, $perPage, ['path' => Paginator::resolveCurrentPath()]); $articles->setPath(""); $tags = $this->tag->all(); $categories = $this->category->all(); return view('frontend.article.index', compact('articles', 'tags', 'categories')); }
/** * Constructor. * @param Collection|LengthAwarePaginator $collection * @param string $class - optional */ public function __construct($collection, $class = null) { if ($collection instanceof LengthAwarePaginator) { $this->paginator = $collection; $this->items = $collection->getCollection(); } else { $this->items = $collection; } if ($class) { $this->setClass($class); } }
public function afterLoad() { $linkedWidget = $this->widgetManager->getWidgetById($this->linked_widget_id); $paginator = null; if (!is_null($linkedWidget) and $linkedWidget instanceof WidgetPaginator) { $paginator = new LengthAwarePaginator([], $linkedWidget->getTotalDocuments(), $linkedWidget->list_size); $paginator->setPageName($this->query_key); $paginator->setPath(Request::path()); $linkedWidget->list_offset = (int) (($paginator->currentPage() - 1) * $paginator->perPage()); } $this->paginator = $paginator; }
public function getIndex(Request $request, Bus $bus) { $userId = $request->user()->id; $page = $request->input('page') ?: 1; $perPage = config('inoplate.notification.per_page', 10); $items = collect($this->notifRepository->get($userId, $page, $perPage)); $total = $this->notifRepository->count($userId); $paginator = new LengthAwarePaginator($items, $total, $perPage, $page); $paginator->setPath('/admin/inoplate-notification/notifications'); $items = $paginator->items(); return $this->getResponse('inoplate-notification::notifications.index', ['notifications' => $paginator->toArray()]); }
/** * Return table pagination data. * * @param Table $table * @return array */ public function make(Table $table) { $options = $table->getOptions(); $perPage = $options->get('limit') ?: config('streams::system.per_page'); $pageName = $table->getOption('prefix') . 'page'; $page = app('request')->get($pageName); $path = '/' . app('request')->path(); $paginator = new LengthAwarePaginator($table->getEntries(), $options->get('total_results', 0), $perPage, $page, compact('path', 'pageName')); $pagination = $paginator->toArray(); $pagination['links'] = $paginator->appends(app('request')->all())->render(); return $pagination; }
/** * List builds. * * @return void */ public function index() { $page = Input::get('page', 1); $perPage = 10; $isLock = $this->locker->isLock(); $pagiData = $this->build->byPage($page, $perPage); $builds = new Paginator($pagiData->items, $pagiData->totalItems, $perPage); $builds->setPath('/' . config('ngmy-stand-ci')['route_prefix'] . '/builds'); if (Request::header('X-PJAX')) { return View::make('stand-ci::builds.index_pjax', array('builds' => $builds, 'isLock' => $isLock)); } else { return View::make('stand-ci::builds.index', array('builds' => $builds, 'isLock' => $isLock)); } }
public function transformPaginated(LengthAwarePaginator $paginator) { $collection = $paginator->getCollection(); try { $transformer = TransformerFactory::makeForCollection($collection); $resource = new Collection($collection, $transformer); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); return $this->manager->createData($resource)->toArray(); } catch (\OutOfRangeException $e) { $emptyResource = new Collection([], []); $emptyResource->setPaginator(new IlluminatePaginatorAdapter($paginator)); return $this->manager->createData($emptyResource)->toArray(); } }
public function getIndex(Request $request) { $page = $request->input('page') ?: 1; $visibility = $request->input('visibility'); $ownership = $request->input('ownership'); $search = $request->input('search'); $perPage = config('inoplate.media.library.per_page', 10); $items = collect($this->libraryRepository->get($page, $search, $visibility, $ownership)); $total = $this->libraryRepository->count(); $items->transform(function ($item, $key) { return $this->generateReturnedData($item->toArray()); }); $paginator = new LengthAwarePaginator($items, $total, $perPage, $page); $paginator->setPath('/admin/inoplate-media/libraries'); return $this->getResponse('inoplate-media::library.index', ['libraries' => $paginator->toArray()]); }
/** * Create a new paginator instance. * * @param mixed $items * @param int $total * @param int $perPage * @param int|null $currentPage * @param array $options (path, query, fragment, pageName) * @return void */ public function __construct($items, $total, $perPage, $currentPage = null, array $options = []) { parent::__construct($items, $total, $perPage, $currentPage, $options); foreach (request()->query->all() as $key => $param) { $this->addQuery($key, $param); } }
/** * Show a list of all contacts By Parent * * @return View */ public function getIndexByParent($parent_id) { // Title $title = 'Boite de réception'; try { $page = Input::get('page', 1); $limit = Input::get('limit', 10); $sortBy = Input::get('sortBy', 'sort_order'); $sortDirection = Input::get('sortDirection', 'desc'); $data = $this->model->getByPage($page, $limit, $sortBy, $sortDirection, []); $totalItems = $data->totalItems; $limit = $data->limit; $models = Paginator::make($data->items, $data->totalItems, $data->limit); } catch (RequestException $e) { echo $e->getRequest() . "\n"; if ($e->hasResponse()) { echo $e->getResponse() . "\n"; } exit; } JavaScript::put(['locale' => LaravelLocalization::setLocale(), 'collection' => $models->getcollection()->toJson()]); $data = array('title' => $title, 'models' => $models, 'totalItems' => $totalItems, 'limit' => $limit, 'sortBy' => $sortBy, 'sortDirection' => $sortDirection, 'routes' => array('create' => 'admin/contacts/create')); // Show the page return View::make('admin.index', $data); }