Exemplo n.º 1
1
 /**
  * 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);
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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]);
 }
Exemplo n.º 4
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()]);
 }
Exemplo n.º 5
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]);
 }
 /**
  * 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()]);
 }
Exemplo n.º 7
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]);
 }
Exemplo n.º 8
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);
 }
 /**
  * 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()]);
 }
Exemplo n.º 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']);
 }
Exemplo n.º 11
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()));
 }
Exemplo n.º 12
0
 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]);
 }
Exemplo n.º 13
0
 /**
  * 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()]);
 }
Exemplo n.º 14
0
 /**
  * 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'));
 }
Exemplo n.º 15
0
 /**
  * Build HTML::title() callback.
  *
  * @param  \Illuminate\Contracts\Foundation\Application  $app
  *
  * @return callable
  */
 protected function buildHtmlTitleCallback(Application $app)
 {
     return function ($title = null) use($app) {
         $title = $title ?: trim(get_meta('title', ''));
         $page = Paginator::resolveCurrentPage();
         $data = ['site' => ['name' => memorize('site.name')], 'page' => ['title' => $title, 'number' => $page]];
         $data['site']['name'] = $this->getHtmlTitleFormatForSite($data);
         $output = $this->getHtmlTitleFormatForPage($data);
         return $app->make('html')->create('title', trim($output));
     };
 }
Exemplo n.º 16
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);
 }
Exemplo n.º 17
0
 public function foldersForCrud(Request $request)
 {
     try {
         $folders = $this->questionService->getFoldersForCrud($request->get('page_size'));
     } catch (QuestionServiceException $e) {
         return Response::json(['error' => $e->getMessage()], 404);
     }
     $page = (int) Paginator::resolveCurrentPage();
     if ($page !== $folders->currentPage()) {
         return Response::json(['error' => 'not found'], 404, [], JSON_NUMERIC_CHECK);
     }
     return Response::json([['total_entries' => $folders->total(), 'currentPage' => $folders->currentPage()], $folders->items()], 200, [], JSON_NUMERIC_CHECK);
 }
Exemplo n.º 18
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()]);
 }
Exemplo n.º 19
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()]);
 }
 /**
  * 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 {
     }
 }
Exemplo n.º 21
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $page = Paginator::resolveCurrentPage();
     $users = User::orderBy('id', 'desc');
     if ($request->input('id')) {
         $users = $users->where('id', '=', $request->input('id'));
     }
     if ($request->input('email')) {
         $users = $users->where('email', 'LIKE', '%' . $request->input('email') . '%');
     }
     if ($request->input('user_name')) {
         $users = $users->where('user_name', 'LIKE', '%' . $request->input('user_name') . '%');
     }
     $users = $users->paginate(10);
     return view('admin.user.index', ['users' => $users, 'f_id' => $request->input('id'), 'f_email' => $request->input('email'), 'f_user_name' => $request->input('user_name'), 'page' => $page]);
 }
Exemplo n.º 22
0
 public function index(Request $request)
 {
     $pageSize = $request->get('page_size');
     try {
         $users = $this->authService->getAllUsers($pageSize);
     } catch (AuthException $e) {
         return Response::json(['error' => ['message' => $e->getMessage()]], 404);
     }
     $page = (int) Paginator::resolveCurrentPage();
     if (empty($page)) {
         $page = 1;
     }
     if ($page !== $users->currentPage()) {
         return Response::json(['error' => 'not found'], 404, [], JSON_NUMERIC_CHECK);
     }
     return Response::json([['total_entries' => $users->total(), 'currentPage' => $users->currentPage()], $users->items()], 200, [], JSON_NUMERIC_CHECK);
 }
 /**
  * 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;
 }
Exemplo n.º 24
0
 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]);
 }
Exemplo n.º 25
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;
 }
 /**
  * Obtiene las obras de un usuario cadeco de todas las bases de datos definidas
  *
  * @param $idUsuario
  * @return Collection|Obra
  */
 public function getObras($idUsuario)
 {
     $obrasUsuario = new Collection();
     $basesDatos = BaseDatosCadeco::where('activa', true)->orderBy('nombre')->get();
     foreach ($basesDatos as $bd) {
         $this->config->set('database.connections.cadeco.database', $bd->nombre);
         $usuarioCadeco = $this->getUsuarioCadeco($idUsuario);
         $obras = $this->getObrasUsuario($usuarioCadeco);
         foreach ($obras as $obra) {
             $obra->databaseName = $bd->nombre;
             $obrasUsuario->push($obra);
         }
         DB::disconnect('cadeco');
     }
     $perPage = 10;
     $currentPage = Paginator::resolveCurrentPage();
     $currentPage = $currentPage ? $currentPage : 1;
     $offset = $currentPage * $perPage - $perPage;
     $paginator = new LengthAwarePaginator($obrasUsuario->slice($offset, $perPage), $obrasUsuario->count(), $perPage);
     return $paginator;
 }
Exemplo n.º 27
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $folder = $request->get('folder');
     $search = $request->get('search');
     $tag = $request->get('tag');
     /** @var \Illuminate\Pagination\LengthAwarePaginator $questions */
     if (empty($search) && empty($folder) && !empty($tag)) {
         $questions = $this->questionService->getQuestions($request->get('page_size'), ['tag' => $tag]);
     } elseif (empty($search) && empty($tag) && !empty($folder)) {
         $questions = $this->questionService->getQuestions($request->get('page_size'), ['folder' => $folder]);
     } else {
         $questions = $this->questionService->getQuestions($request->get('page_size'));
     }
     $page = (int) Paginator::resolveCurrentPage();
     if (empty($page)) {
         $page = 1;
     }
     if ($page !== $questions->currentPage()) {
         return Response::json(['error' => 'not found'], 404, [], JSON_NUMERIC_CHECK);
     }
     return Response::json([['total_entries' => $questions->total(), 'currentPage' => $questions->currentPage()], $questions->items()], 200, [], JSON_NUMERIC_CHECK);
 }
 /**
  * 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()];
 }
Exemplo n.º 29
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $type = $request->get('type');
     if (empty($type)) {
         $type = 'list';
     }
     switch ($type) {
         case 'popular':
             $tags = $this->questionService->getTagsPopular($request->get('page_size'));
             $page = (int) Paginator::resolveCurrentPage();
             if (empty($page)) {
                 $page = 1;
             }
             if ($page !== $tags->currentPage()) {
                 return Response::json(['error' => 'not found'], 404, [], JSON_NUMERIC_CHECK);
             }
             $result = $tags->items();
             break;
         case 'search':
             $result = $this->questionService->getTags($request->get('page_size'));
             break;
         case 'list':
             $tags = $this->questionService->getTagsPopular($request->get('page_size'), $request->get('search'));
             $page = (int) Paginator::resolveCurrentPage();
             if (empty($page)) {
                 $page = 1;
             }
             if ($page !== $tags->currentPage()) {
                 return Response::json(['error' => 'not found'], 404, [], JSON_NUMERIC_CHECK);
             }
             $result = [['total_entries' => $tags->total(), 'currentPage' => $tags->currentPage()], $tags->items()];
             break;
         default:
             $result = [];
     }
     return Response::json($result, 200, [], JSON_NUMERIC_CHECK);
 }
Exemplo n.º 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]);
 }