コード例 #1
3
ファイル: User.php プロジェクト: marcocastignoli/lumen_auth
 static function list($number, $page)
 {
     Paginator::currentPageResolver(function () use($page) {
         return $page;
     });
     return self::show("*")->paginate($number);
 }
コード例 #2
1
 /**
  * Paginates the Elasticsearch results.
  *
  * @param int $perPage
  * @return mixed
  */
 public function paginate($perPage = 15)
 {
     $paginator = new Paginator($this->items, $perPage);
     $start = ($paginator->currentPage() - 1) * $perPage;
     $sliced = array_slice($this->items, $start, $perPage);
     return new Paginator($sliced, $perPage);
 }
コード例 #3
1
 /**
  * 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'));
 }
コード例 #4
0
 public function timeLine()
 {
     $tags = Auth::user()->tags()->get();
     $posts = collect([]);
     foreach ($tags as $tag) {
         foreach ($tag->post()->get() as $post) {
             if (!Auth::user()->type) {
                 if (!$post->private) {
                     $posts->push($post);
                 } else {
                     if ($post->user_id == Auth::id()) {
                         $posts->push($post);
                     }
                 }
             } else {
                 $posts->push($post);
             }
         }
     }
     $posts = new Paginator($posts->unique('id'), 10);
     if (strpos(redirect()->back()->getTargetUrl(), 'login') === false) {
         return view('welcome', compact('posts', 'tags'));
     } else {
         return view('welcome', compact('posts', 'tags'))->with('message', 'Welcome ' . Auth::user()->fullName());
     }
 }
コード例 #5
0
ファイル: Fractal.php プロジェクト: huglester/larasponse
 public function paginatedCollection(Paginator $paginator, $transformer = null, $resourceKey = null)
 {
     $paginator->appends(\Request::query());
     $resource = new Collection($paginator->getCollection(), $this->getTransformer($transformer), $resourceKey);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $this->manager->createData($resource)->toArray();
 }
コード例 #6
0
 static function answerOkByPager(Paginator $paginator)
 {
     if ($paginator->getLastPage() == $paginator->getCurrentPage()) {
         $next_page = null;
     } else {
         $next_page = $paginator->getCurrentPage();
     }
     $next_page_url = $next_page ? \Request::url() . '?page=' . $next_page : null;
     return parent::json(['meta' => ['code' => 200], 'pagination' => ['next_url' => $next_page_url, 'next_page' => $next_page], 'data' => $paginator->getCollection()->toArray()], 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
 }
コード例 #7
0
 public function paginator(\Illuminate\Pagination\Paginator &$paginator)
 {
     $items = [];
     foreach ($this as $index => $item) {
         if ($index < $paginator->getFrom() - 1 || $index > $paginator->getTo() - 1) {
             continue;
         }
         $items[] = $item;
     }
     $paginator->setItems($items);
     return $paginator;
 }
コード例 #8
0
ファイル: NumericArray.php プロジェクト: tjbp/tablelegs
 /**
  * Return the paginated dataset of the underlying database.
  *
  * @param int    $perPage
  * @param array  $columns
  * @param string $pageName
  * @param int    $page
  *
  * @return \Illuminate\Pagination\Paginator
  */
 public function paginate($perPage, $columns, $pageName, $page)
 {
     $total = count($this->db);
     $page = $page ?: Paginator::resolveCurrentPage($pageName);
     $results = array_slice($this->get(), ($page - 1) * $perPage, $perPage);
     return new LengthAwarePaginator($results, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
 }
コード例 #9
0
ファイル: LocationLog.php プロジェクト: emyeuheo/phonetracker
 public static function readLog($deviceId, $page)
 {
     Paginator::currentPageResolver(function () use($page) {
         return $page;
     });
     return LocationLog::where('device_id', $deviceId)->orderBy('location_time', 'DESC')->simplePaginate(config('custom.item_per_page'))->all();
 }
コード例 #10
0
 /**
  * @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;
 }
コード例 #11
0
 /**
  * Paginates a collection. For simple pagination, one can override this function
  *
  * a little help from http://laravelsnippets.com/snippets/custom-data-pagination
  *
  * @param Collection $data
  * @param int $perPage
  * @param Request $request
  * @param null $page
  *
  * @return LengthAwarePaginator
  */
 public function paginateCollection(Collection $data, $perPage, Request $request, $page = null)
 {
     $pg = $request->get('page');
     $page = $page ? (int) $page * 1 : (isset($pg) ? (int) $request->get('page') * 1 : 1);
     $offset = $page * $perPage - $perPage;
     return new LengthAwarePaginator($data->splice($offset, $perPage), $data->count(), $perPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
 }
コード例 #12
0
 /**
  * Set the current page based on the page route parameter before the route's action is executed.
  *
  * @return \Illuminate\Http\Request
  */
 public function handle($request, Closure $next)
 {
     Paginator::currentPageResolver(function () {
         return app('paginateroute')->currentPage();
     });
     return $next($request);
 }
コード例 #13
0
 /**
  * Список новостей
  * @param Request $request
  * @param null $alias
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function feed(Request $request, $alias = null)
 {
     $page = Paginator::resolveCurrentPage('page');
     $per_page = config('paginator.per_page');
     $category = Category::where('alias', $alias)->first();
     $order_by = $request->input('order_by');
     $articles = Article::whereRaw('1=1');
     switch ($order_by) {
         case 'name_desc':
             $articles->orderBy('name', 'desc');
             break;
         case 'name_asc':
             $articles->orderBy('name', 'asc');
             break;
         case 'date_desc':
             $articles->orderBy('created_at', 'desc');
             break;
         case 'date_asc':
             $articles->orderBy('created_at', 'asc');
             break;
         default:
             $articles->orderBy('created_at', 'desc');
             break;
     }
     if (is_null($category)) {
         $articles = $articles->paginate($per_page);
     } else {
         $articles = $articles->where('category_id', $category->id)->paginate($per_page);
     }
     if ($order_by) {
         $articles->appends('order_by', $order_by);
     }
     return view('pages/feed', ['articles' => $articles, 'category' => $category, 'page' => $page, 'order_by' => $order_by]);
 }
コード例 #14
0
 public function validateQuery(Request $request)
 {
     $modelClass = $this->model;
     $queryBuilder = new $modelClass();
     if (count($parameters = $request->all()) > 0) {
         $handledRequestParameters = $this->handleRequestParameters($parameters);
         if (isset($handledRequestParameters['queries'])) {
             foreach ($handledRequestParameters['queries'] as $query) {
                 $queryBuilder = $this->handleQuery($queryBuilder, $query);
             }
         }
         if (isset($handledRequestParameters['take'])) {
             $queryBuilder = $queryBuilder->take($handledRequestParameters['take']);
         } else {
             if (isset($handledRequestParameters['pagination'])) {
                 $currentPage = $handledRequestParameters['pagination']['page'];
                 Paginator::currentPageResolver(function () use($currentPage) {
                     return $currentPage;
                 });
                 return $queryBuilder = $queryBuilder->paginate($handledRequestParameters['pagination']['paginate'])->setPath($this->getUrlParameters($request));
             }
         }
     }
     return $queryBuilder->get();
 }
コード例 #15
0
 /**
  * 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;
 }
コード例 #16
0
ファイル: Content.php プロジェクト: mikegit2014/laravelback
 /**
  * 取得未删除的信息
  *
  * @return array
  * @todo 数据量多时,查找属于指定分类,推荐位,标签三个的文章时使用redis集合交集处理,避免查询消耗。
  */
 public function AllContents($search = [])
 {
     $prefix = \DB::getTablePrefix();
     $currentQuery = $this->select(['article_main.*', 'users.name'])->leftJoin('users', 'article_main.user_id', '=', 'users.id')->leftJoin('article_classify_relation', 'article_main.id', '=', 'article_classify_relation.article_id')->leftJoin('article_classify', 'article_classify_relation.classify_id', '=', 'article_classify.id')->leftJoin('article_position_relation', 'article_main.id', '=', 'article_position_relation.article_id')->leftJoin('article_tag_relation', 'article_main.id', '=', 'article_tag_relation.article_id')->orderBy('article_main.id', 'desc')->where('article_main.is_delete', self::IS_DELETE_NO)->groupBy('article_main.id')->distinct();
     if (isset($search['keyword']) && !empty($search['keyword'])) {
         $currentQuery->where('article_main.title', 'like', "%{$search['keyword']}%");
     }
     if (isset($search['username']) && !empty($search['username'])) {
         $currentQuery->where('article_main.user_id', $search['username']);
     }
     if (isset($search['classify']) && !empty($search['classify'])) {
         $currentQuery->where('article_classify_relation.classify_id', $search['classify']);
     }
     if (isset($search['position']) && !empty($search['position'])) {
         $currentQuery->where('article_position_relation.position_id', $search['position']);
     }
     if (isset($search['tag']) && !empty($search['tag'])) {
         $currentQuery->where('article_tag_relation.tag_id', $search['tag']);
     }
     if (isset($search['timeFrom'], $search['timeTo']) and !empty($search['timeFrom']) and !empty($search['timeTo'])) {
         $search['timeFrom'] = strtotime($search['timeFrom']);
         $search['timeTo'] = strtotime($search['timeTo']);
         $currentQuery->whereBetween('article_main.write_time', [$search['timeFrom'], $search['timeTo']]);
     }
     $total = count($currentQuery->get()->all());
     $currentQuery->forPage($page = Paginator::resolveCurrentPage(), $perPage = self::PAGE_NUMS);
     $result = $currentQuery->get()->all();
     return new LengthAwarePaginator($result, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath()]);
 }
コード例 #17
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($projectId, $versionId, $id, Request $request)
 {
     $w = $request->input('w', self::ASC);
     if (!$w || strcmp("", trim($w)) === 0 || !in_array(trim($w), [self::ASC, self::DESC]) || strcmp(sprintf("%d", self::DESC), trim($w)) === 0) {
         $w = self::ASC;
     } else {
         $w = self::DESC;
     }
     //$o = $request->input('o', /* only option*/ 3);
     $o = 3;
     $version = $this->versionsGateway->findById($versionId);
     $project = $version['project_artifact'];
     Debugbar::info($version);
     // $testRuns = $this->testRunsGateway->findByVersionId($version['id']);
     // Debugbar::info($testRuns);
     $testRun = $this->testRunsGateway->findById($id, $o, $w);
     Debugbar::info($testRun);
     $tests = $testRun['tests'];
     Debugbar::info($tests);
     $paginator = new LengthAwarePaginator($tests['data'], $tests['total'], $tests['per_page'], Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath(), 'query' => ["o" => $o, "w" => $w]]);
     Debugbar::info($paginator);
     $letter = strtoupper($project['name'][0]);
     $user = $testRun['user'];
     $data = array('projectId' => $projectId, 'versionId' => $versionId, 'version' => $version, 'project' => $project, 'id' => $id, 'testRun' => $testRun, 'letter' => $letter, 'user' => $user, 'tests' => $tests['data'], 'paginator' => $paginator, 'w' => $w);
     return view('test_run', $data);
 }
コード例 #18
0
 public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
 {
     $page = $page ?: Paginator::resolveCurrentPage($pageName);
     $total = $this->count();
     $results = $this->forPage($page, $perPage);
     return new LengthAwarePaginator($results, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
 }
コード例 #19
0
ファイル: ElasticCollection.php プロジェクト: mozzos/bouncy
 /**
  * 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']);
 }
コード例 #20
0
 /**
  * Set the current page based on the page route parameter before the route's action is executed.
  * 
  * @return \Illuminate\Http\Request
  */
 public function handle($request, Closure $next)
 {
     $page = Route::getCurrentRoute()->parameter('page', 1);
     Paginator::currentPageResolver(function () use($page) {
         return $page;
     });
     return $next($request);
 }
コード例 #21
0
ファイル: Grid.php プロジェクト: reillo/grid
 /**
  * Prepare query for pagination
  *
  * @return $this
  */
 protected function preparePagination()
 {
     $this->setQuerySortable();
     // set paginator
     $this->paginator = $this->getQuery()->paginate($this->getPerPage());
     $this->paginator->appends(Request::except('ajax'));
     return $this;
 }
コード例 #22
0
ファイル: LogController.php プロジェクト: MehmetNuri/fullycms
 public function index()
 {
     $level = Input::get('levels', 'all');
     $levels = array('all' => 'ALL', 'debug' => 'DEBUG', 'info' => 'INFO', 'notice' => 'NOTICE', 'warning' => 'WARNING', 'error' => 'ERROR', 'critical' => 'CRITICAL', 'alert' => 'ALERT', 'emergency' => 'EMERGENCY');
     $logs = LogViewer::getLogs($level);
     $paginator = new LengthAwarePaginator($logs, count($logs), 25, ['path' => Paginator::resolveCurrentPath()]);
     return view('backend.log.index', compact('paginator', 'levels', 'level'));
 }
コード例 #23
0
 /**
  * create aLengthAwarePaginator from an Eloquent Request
  * This is useful because Laravel 5 only provide a simple paginator
  * out of the box.
  *
  * @param $builder
  * @param $perPage
  * @return LengthAwarePaginator
  */
 function createPaginator($builder, $perPage)
 {
     $page = Paginator::resolveCurrentPage();
     $builder->skip(($page - 1) * $perPage)->take($perPage + 1);
     $queryClone = clone $builder->getQuery();
     $total = $queryClone->skip(0)->take($perPage + 1)->count();
     return new LengthAwarePaginator($builder->get(), $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath()]);
 }
コード例 #24
0
ファイル: Devs.php プロジェクト: beeblebrox3/devshop
 private function parseRequestPagination($query)
 {
     $page = (int) $this->getHttp()->getInput('page', 1);
     $offset = (int) $this->getHttp()->getInput('offset', 2);
     \Illuminate\Pagination\Paginator::currentPageResolver(function () use($page) {
         return $page;
     });
     return $query->paginate($offset);
 }
コード例 #25
0
 /**
  * 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'));
 }
コード例 #26
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->mergeConfigFrom(__DIR__ . '/../config/tabulator.php', 'tabulator');
     if (config('tabulator.css-framework') == 'foundation') {
         Paginator::presenter(function ($paginator) {
             return new FoundationPresenter($paginator);
         });
     }
 }
コード例 #27
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     Paginator::currentPathResolver(function () {
         return $this->app['slim']->request->getResourceUri();
     });
     Paginator::currentPageResolver(function ($pageName = 'page') {
         return $this->app['slim']->request->params($pageName);
     });
 }
コード例 #28
0
ファイル: ArrayPaginator.php プロジェクト: aerojun/pcmrcritic
 /**
  * Create paginator
  *
  * @param  array  $items
  * @param  int    $perPage
  * @return LengthAwarePaginator
  */
 public function paginate($items, $perPage)
 {
     $pageStart = \Request::get('page', 1);
     // Start displaying items from this number;
     $offSet = $pageStart * $perPage - $perPage;
     // Get only the items you need using array_slice
     $itemsForCurrentPage = array_slice($items, $offSet, $perPage, true);
     return new LengthAwarePaginator($itemsForCurrentPage, count($items), $perPage, Paginator::resolveCurrentPage(), array('path' => Paginator::resolveCurrentPath()));
 }
コード例 #29
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     Paginator::currentPathResolver(function () {
         return $this->app['request']->url();
     });
     Paginator::currentPageResolver(function () {
         return $this->app['request']->input('page');
     });
 }
コード例 #30
-15
ファイル: Response.php プロジェクト: ryanmcoble/remedy
 /**
  * Respond with a paginator, and a transformer.
  *
  * @param Paginator $paginator
  * @param callable|\League\Fractal\TransformerAbstract $transformer
  * @param string $resourceKey
  * @param array $meta
  * @return \Illuminate\Http\Response
  */
 public function withPaginator(Paginator $paginator, $transformer, $resourceKey = null, $meta = [])
 {
     $resource = new Collection($paginator->getCollection(), $transformer, $resourceKey);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     foreach ($meta as $metaKey => $metaValue) {
         $resource->setMetaValue($metaKey, $metaValue);
     }
     $rootScope = $this->manager->createData($resource);
     return $this->withArray($rootScope->toArray());
 }