/**
  * 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'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $letter = $request->input('letter');
     if (!isset($letter) || !$letter) {
         $projects = $this->projectsGateway->findFeaturedProjects();
         Debugbar::info($projects);
         $data = array('letter' => strtoupper($letter), 'projects' => $projects);
         return view('projects', $data);
     }
     $projects = $this->projectsGateway->findProjectsByLetter($letter);
     $paginator = new LengthAwarePaginator($projects['data'], $projects['total'], $projects['per_page'], Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
     Debugbar::info($projects);
     $data = array('letter' => strtoupper($letter), 'projects' => $projects['data'], 'paginator' => $paginator);
     return view('projects_by_letter', $data);
 }
 /**
  * @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;
 }
Exemple #4
0
 /**
  * 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]);
 }
Exemple #5
0
 /**
  * 取得未删除的信息
  *
  * @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()]);
 }
 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]);
 }
 /**
  * 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;
 }
 /**
  * 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()]);
 }
 /**
  * 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);
 }
Exemple #10
0
 /**
  * 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']);
 }
Exemple #11
0
 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'));
 }
 /**
  * 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()]);
 }
Exemple #13
0
 /**
  * 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()));
 }
 /**
  * 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'));
 }
 /**
  * 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'));
 }
 /**
  * Show feeds from a specific provider
  *
  * @param $provider_id
  * @param Request $request
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function show($provider_id, Request $request)
 {
     $feedsPerPage = 10;
     $page = $request->has('page') ? $request->get('page') : 1;
     $provider = Provider::findOrFail($provider_id);
     $feedArray = $this->createFeedsFromProvider($provider, $request->get('srch-term'));
     $pageFeedArray = array_slice($feedArray, ($page - 1) * $feedsPerPage, ($page - 1) * $feedsPerPage + $feedsPerPage);
     $paginator = new LengthAwarePaginator($pageFeedArray, count($feedArray), $feedsPerPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
     return view('providers.show', compact('provider', 'paginator'));
 }
 public function paginate($perPage = 15, $columns = array('*'))
 {
     $this->model->underlyingQuery()->orderBy('created_at', 'desc')->orderBy('id', 'desc');
     $perPage = $perPage ?: $this->entriesPerPage();
     $pageName = 'page';
     $query = $this->model->underlyingQuery();
     $total = $query->getQuery()->getCountForPagination();
     $query->forPage($page = Paginator::resolveCurrentPage($pageName), $perPage = $perPage ?: $this->model->model->getPerPage());
     return new UpdatesPaginator($query->get($columns), $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
 }
 /**
  * A custom paginate method for when using the distinct() method. This fixes the incorrect 'total' reported by the default paginate.
  * @param        $query
  * @param int    $perPage
  * @param array  $columns
  * @param string $pageName
  * @return \Illuminate\Pagination\LengthAwarePaginator
  */
 public function scopeDistinctPaginate($query, $perPage = 15, $columns = ['*'], $pageName = 'page')
 {
     // Get the results
     $results = $query->forPage(Input::get($pageName, 1), $perPage)->get($columns);
     // Now do a count on an unlimited version of the previous query
     $query->limit(static::count())->offset(0);
     $count = DB::select("SELECT COUNT(*) FROM (" . $query->toSql() . ") src;", $query->getBindings())[0]->{"COUNT(*)"};
     // Create the paginator
     return new LengthAwarePaginator($results, $count, $perPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
 }
 public function index()
 {
     $q = Input::get('search');
     View::composer('frontend/layout/menu', function ($view) use($q) {
         $view->with('q', $q);
     });
     $result = Search::search($q);
     $paginator = new LengthAwarePaginator($result, count($result), 10, ['path' => Paginator::resolveCurrentPath()]);
     return view('frontend.search.index', compact('paginator', 'q'));
 }
 /**
  * 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'));
 }
Exemple #21
0
 public function index(Request $request)
 {
     $perPage = 10;
     $page = $request->input('page', 1);
     $pagiData = $this->repositorio_personas->obtenerPaginados($page, $perPage);
     $documento = app()->make(config('usuarios.modelo_documento'));
     $paises = app()->make(config('usuarios.modelo_pais'));
     $etnias = app()->make(config('usuarios.modelo_etnia'));
     $lista = ['personas' => new LengthAwarePaginator($pagiData->items, $pagiData->totalItems, $perPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]), 'documentos' => $documento->all(), 'paises' => $paises->all(), 'etnias' => $etnias->all(), 'status' => session('status')];
     $datos = ['seccion' => config('usuarios.seccion'), 'lista' => view(config('usuarios.lista'), $lista)];
     return view(config('usuarios.vista_lista'), $datos);
 }
Exemple #22
0
 public function getPaginator()
 {
     if (!$this->paginator) {
         $items = $this->getCollection()->toArray();
         if (version_compare(Application::VERSION, '5.0.0', '<')) {
             $this->paginator = \Paginator::make($items, $this->getTotalRowsCount(), $this->page_size);
         } else {
             $this->paginator = new \Illuminate\Pagination\LengthAwarePaginator($items, $this->getTotalRowsCount(), $this->page_size, $this->getCurrentPage(), ['path' => \Illuminate\Pagination\Paginator::resolveCurrentPath()]);
         }
     }
     return $this->paginator;
 }
Exemple #23
0
 /**
  * 取得文章列表信息
  * 
  * @return array
  */
 public function activeArticleInfo($object)
 {
     $this->prefix = \DB::getTablePrefix();
     $currentQuery = $this->select(\DB::raw($this->prefix . 'article_main.*'))->leftJoin('article_classify_relation', 'article_classify_relation.article_id', '=', 'article_main.id')->leftJoin('article_classify', 'article_classify_relation.classify_id', '=', 'article_classify.id')->leftJoin('article_tag_relation', 'article_tag_relation.article_id', '=', 'article_main.id')->leftJoin('article_tags', 'article_tag_relation.tag_id', '=', 'article_tags.id')->where('article_main.is_delete', self::IS_DELETE_NO)->where('article_main.status', self::STATUS_YES)->groupBy('article_main.id')->orderBy('article_main.id', 'desc');
     if (isset($object->category) and is_numeric($object->category) and !empty($object->category)) {
         $currentQuery->where('article_classify.id', $object->category);
     }
     if (isset($object->tag) and is_numeric($object->tag) and !empty($object->tag)) {
         $currentQuery->where('article_tags.id', $object->tag);
     }
     $total = $currentQuery->get()->count();
     $currentQuery->forPage($page = Paginator::resolveCurrentPage(), $perPage = 20);
     $data = $currentQuery->get()->all();
     return new LengthAwarePaginator($data, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath()]);
 }
Exemple #24
0
 /**
  * 搜索查询取得文章列表信息
  * 
  * @return array
  */
 public function activeArticleInfoBySearch($object)
 {
     //\DB::connection()->enableQueryLog();
     if (!isset($object->sphinxResult_ArticleIds) or !is_array($object->sphinxResult_ArticleIds)) {
         return [];
     }
     $this->prefix = \DB::getTablePrefix();
     $currentQuery = $this->select(\DB::raw($this->prefix . 'article_main.*, group_concat(DISTINCT ' . $this->prefix . 'article_classify.name) as classnames, group_concat(DISTINCT ' . $this->prefix . 'article_tags.name) as tagsnames'))->leftJoin('article_classify_relation', 'article_classify_relation.article_id', '=', 'article_main.id')->leftJoin('article_classify', 'article_classify_relation.classify_id', '=', 'article_classify.id')->leftJoin('article_tag_relation', 'article_tag_relation.article_id', '=', 'article_main.id')->leftJoin('article_tags', 'article_tag_relation.tag_id', '=', 'article_tags.id')->where('article_main.is_delete', self::IS_DELETE_NO)->where('article_main.status', self::STATUS_YES)->whereIn('article_main.id', $object->sphinxResult_ArticleIds)->groupBy('article_main.id')->orderBy('article_main.id', 'desc');
     $total = $currentQuery->get()->count();
     $currentQuery->forPage($page = Paginator::resolveCurrentPage(), $perPage = 20);
     $data = $currentQuery->get()->all();
     //$queries = \DB::getQueryLog();
     //dd($total, $queries);
     return new LengthAwarePaginator($data, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath()]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($specialty = '', $location = '')
 {
     // Prepare query search result set
     $this->data['options'] = new DataLoader();
     $this->data['location'] = $this->data['options']->getIdValue($location, 'location_cities');
     $this->data['specialty'] = $this->data['options']->getIdValue($specialty, 'specializations');
     // Prepare additional query
     $location_query = $location ? array($this->data['location']->id) : array();
     if (isset($_GET['locations'])) {
         if ($_GET['locations']) {
             $location_query = array_merge($location_query, explode('-', $_GET['locations']));
         }
     }
     $specialty_query = $specialty ? array($this->data['specialty']->id) : array();
     if (isset($_GET['specialty'])) {
         if ($_GET['specialty']) {
             $specialty_query = array_merge($specialty_query, explode('-', $_GET['specialty']));
         }
     }
     $this->data['query'] = array('specializations' => $specialty_query, 'locations' => $location_query);
     $this->data['ip'] = $_SERVER['REMOTE_ADDR'] == '127.0.0.1' ? '112.199.47.222' : $_SERVER['REMOTE_ADDR'];
     $this->data['ip_loc'] = json_decode(file_get_contents('http://ipinfo.io/' . $this->data['ip'] . '/json'));
     $ch = curl_init('http://ipinfo.io/' . $this->data['ip'] . '/json');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $this->data['ip_loc'] = json_decode(curl_exec($ch));
     $this->data['coordiantes'] = explode(",", $this->data['ip_loc']->loc);
     $this->data['doctors_list'] = $this->data['options']->buildDoctorsList($this->data['coordiantes'][0], $this->data['coordiantes'][1], isset($_GET['page']) ? $_GET['page'] < 2 ? 0 : ($_GET['page'] == 2 ? 25 : ($_GET['page'] - 1) * 25) : 0, 25, $this->data['query']);
     $this->data['doctors'] = json_decode($this->data['doctors_list']);
     $this->doctor = new Doctors();
     $this->data['list_count'] = $this->doctor->getDoctorsListCount($this->data['coordiantes'][0], $this->data['coordiantes'][1], $this->data['query']);
     $this->data['paginator'] = new LengthAwarePaginator($this->data['doctors_list'], count($this->data['list_count']), 25, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
     // Prepare page title
     if ($specialty && $location) {
         $this->data['title'] = config('constants.general_title') . ' - Doctors of ' . $this->data['specialty']->specialization . ' in ' . $this->data['location']->city_name;
     } else {
         $this->data['title'] = config('constants.general_title') . ' - Doctors in the Philippines listed';
     }
     // Load data for both specialties and locations dropdown search
     $this->data['specialties'] = DB::table('specializations')->get();
     $this->data['locations'] = json_decode($this->data['options']->getLocations('provinces'));
     // Load data for sidebar options of locations and specialties
     $this->data['opt_specs'] = DB::table('specializations')->take(10)->get();
     $this->data['opt_locs'] = $this->data['options']->getOptionsLocations($location ? $this->data['location']->province_id : 0);
     if ($location && $specialty) {
         return view('doctors.index')->with($this->data);
     } else {
     }
 }
 public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
 {
     $this->columns = $columns;
     $page = $page ?: Paginator::resolveCurrentPage($pageName);
     $perPage = $perPage ?: $this->builder->getPerPage();
     $query = $this->builder->toBase();
     $key = 'criteria:' . get_class($this->builder->getModel()) . ':' . $this->getQueryHash() . ':count';
     $total = Cache::remember($key, config('collejo.pagination.perpage'), function () use($key, $query) {
         return $query->getCountForPagination();
     });
     $results = new Collection();
     if ($total) {
         $this->builder->forPage($page, $perPage);
         $results = $this->getResult();
     }
     return new LengthAwarePaginator($results, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
 }
 /**
  * Performs a paginated search against Elastic Search
  * 
  * @param Array $query Array containing the elastic search query
  * @param string $index Index to search in (optional)
  * @param string $type Type of document to search for (optional)
  * @return LengthAwarePaginator paginated result of the search
  */
 public static function search($query, $index = null, $type = null)
 {
     $perPage = Request::input('perPage', 10);
     $from = $perPage * (Request::input('page', 1) - 1);
     $query['highlight'] = array('fields' => array('*' => (object) array()));
     $searchParams = array('body' => $query, 'size' => $perPage, 'from' => $from);
     if ($index) {
         $searchParams['index'] = $index;
     }
     if ($type) {
         $searchParams['type'] = $type;
     }
     $client = self::getClient();
     $queryResponse = $client->search($searchParams);
     $paginator = new ElasticSearchPaginator($queryResponse['hits']['hits'], $queryResponse['hits']['total'], $perPage, $queryResponse['aggregations'], Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
     return $paginator;
 }
Exemple #28
0
 /**
  * Полнотекстовый поиск с разбивкой на страницы
  * @param $request
  * @return LengthAwarePaginator
  */
 public static function search($request)
 {
     $results = [];
     $search = $request->input('q');
     $path = Paginator::resolveCurrentPath();
     $page = Paginator::resolveCurrentPage('page');
     $per_page = config('paginator.per_page');
     $offset = ((int) $page - 1) * $per_page;
     $sql = 'SELECT SQL_CALC_FOUND_ROWS A.*, MATCH(A.name, A.text) AGAINST (?) AS score
             FROM articles AS A
             WHERE MATCH(A.name, A.text) AGAINST (?)
             ORDER BY score DESC, A.name ASC LIMIT ? OFFSET ?';
     $articles_ids = DB::select($sql, [$search, $search, $per_page, $offset]);
     $total = DB::select('SELECT FOUND_ROWS() AS total')[0]->total;
     foreach ($articles_ids as $item) {
         $results[] = Article::find($item->id);
     }
     $paginator = new LengthAwarePaginator($results, $total, $per_page, $page, ['path' => $path]);
     $paginator->appends('q', $search);
     return $paginator;
 }
 /**
  * Paginate Load More
  *
  * Paginates an eloquent Model's results with an initial quantity of items
  * on the first page and then another quantity on subsequent pages
  *
  * @param  Illuminate\Database\Query\Builder $query     [An Eloquent Query Builder]
  * @param  integer $initialQuantity [Quantity of items on the first page]
  * @param  integer $loadMore        [Quantity of items on subsequent pages]
  * @param  Illuminate\Database\Eloquent\Model $model [An Eloquent Model]
  *
  * @return array [Array of results and pagination information]
  */
 public function paginatedLoadMore($initialQuantity = 9, $loadMore = 3, $model = null)
 {
     // If no model is passed as last argument and current class is not an Eloquent Model then abort
     if ($model === null && !$this instanceof Model) {
         throw new ModelClassRequiredException();
     }
     // Model is either the model passed as last argument or the Class in case it is null
     $model = $model ?: $this;
     $page = (int) Paginator::resolveCurrentPage();
     $perPage = $page == 1 ? $initialQuantity : $loadMore;
     $skip = $page == 1 ? 0 : $initialQuantity + $loadMore * ($page - 2);
     // Get a full collection to be able to calculate the full total all the time
     $modelCollection = $model->get();
     // Get the correct results
     $modelResults = $model->skip($skip)->take($perPage)->get();
     $total = $modelCollection->count();
     $lastPage = $total > $initialQuantity ? (int) ceil(($total - $initialQuantity) / $loadMore + 1) : 1;
     $from = $skip + 1;
     $to = $total > $initialQuantity ? $skip + $perPage : $total;
     $nextPageUrl = $page !== $lastPage ? (string) Paginator::resolveCurrentPath() . '?page=' . ($page + 1) : null;
     $previousPageUrl = $page !== 1 ? (string) Paginator::resolveCurrentPath() . '?page=' . ($page - 1) : null;
     return ['current_page' => $page, 'per_page' => $perPage, 'total' => $total, 'last_page' => $lastPage, 'from' => $from, 'to' => $to, 'previous_page_url' => $previousPageUrl, 'next_page_url' => $nextPageUrl, 'data' => $modelResults->toArray()];
 }
Exemple #30
0
 /**
  * Get a paginator only supporting simple next and previous links.
  *
  * This is more efficient on larger data-sets, etc.
  *
  * @param  int  $perPage
  * @param  array  $columns
  * @param  string  $pageName
  * @return \Illuminate\Contracts\Pagination\Paginator
  */
 public function simplePaginate($perPage = 15, $columns = ['*'], $pageName = 'page')
 {
     $page = Paginator::resolveCurrentPage($pageName);
     $this->skip(($page - 1) * $perPage)->take($perPage + 1);
     return new Paginator($this->get($columns), $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
 }