/**
  * 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'));
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemple #4
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;
 }
Exemple #5
0
 /**
  * Paginate searched products.
  *
  * @param string $searchTerm
  * @param int $page
  * @return LengthAwarePaginator
  */
 protected static function paginateSearchedProducts($searchTerm, $page)
 {
     // Query for results
     $results = \DB::table('application_products')->where('code', 'like', "{$searchTerm}%")->orWhere('name', 'like', "{$searchTerm}%")->orderBy('created_at', 'desc')->get();
     // Make sure page is always positive
     if ($page < 1) {
         $page = 1;
     }
     $perPage = Settings::displayedBills();
     // Calculate start from
     $startFrom = $perPage * ($page - 1);
     $sliced = array_slice($results, $startFrom, $perPage);
     $paginate = new LengthAwarePaginator($sliced, count($results), $perPage);
     if (isset($searchTerm) && strlen($searchTerm) > 0) {
         $paginate->setPath('/admin-center/products-manager/get/search');
         $paginate->appends(['term' => $searchTerm]);
     } else {
         $paginate->setPath('/admin-center/products-manager/get');
     }
     return $paginate;
 }
 public function build()
 {
     $request = $this->request;
     $needle = $request->needle();
     if ($needle && $request->searchable) {
         $this->qb->where(function ($subQB) use($needle, $request) {
             foreach ($request->searchable as $column) {
                 $subQB->orWhere($column, 'LIKE', "%{$needle}%");
             }
         });
     }
     $request->modifyQuery($this->qb);
     $this->qb->orderBy($request->orderBy(), $request->sortBy());
     $count = $this->qb->count();
     $this->qb->take($request->perPage());
     $this->qb->offset($request->offset());
     $paginator = new LengthAwarePaginator($request->items($this->qb), $count, $request->perPage(), $request->page());
     $paginator->request = $request;
     $paginator->appends($request->query());
     $this->paginator = $paginator;
 }
 /**
  * Perform query and return pagination results.
  *
  * @param string $searchTerm
  * @param int $page
  * @return LengthAwarePaginator
  */
 protected static function paginate($searchTerm, $page)
 {
     // Query database to get results
     $results = DB::table('products')->where('code', 'like', "{$searchTerm}%")->orWhere('name', 'like', "{$searchTerm}%")->orderBy('code', 'asc')->get();
     // Make sure page is always positive
     self::validatePage($searchTerm);
     $perPage = Settings::displayedBills();
     // Calculate start from
     $startFrom = self::getStartFrom($page, $perPage);
     // Slice the results
     $sliced = self::getSlicedResults($results, $startFrom, $perPage);
     // Initialize the paginator
     $paginate = new LengthAwarePaginator($sliced, count($results), $perPage);
     // Check if search term should be appended to the search path
     if (isset($searchTerm) && strlen($searchTerm) > 0) {
         $paginate->setPath('/my-products/get/search');
         $paginate->appends(['term' => $searchTerm]);
     } else {
         $paginate->setPath('/my-products/get');
     }
     return $paginate;
 }
Exemple #8
0
    $useLengthAware = true;
    // Paginator class example
    if (!$useLengthAware) {
        $paginatorItems = array_slice($items, $offset);
        $results = new Paginator($paginatorItems, $perPage, $currentPage, $options);
    }
    // End of Paginator example
    // LengthAwarePaginator class example
    if ($useLengthAware) {
        $lengthAwarePaginatorItems = array_slice($items, $offset, $perPage);
        $results = new LengthAwarePaginator($lengthAwarePaginatorItems, $total, $perPage, $currentPage, $options);
    }
    // End of LengthAwarePaginator example
    // Display a paginated table of our array
    echo '<h1>I love hashes</h1>';
    echo '<table>';
    foreach ($results as $result) {
        echo "\n        <tr>\n            <td>{$result['id']}</td>\n            <td>{$result['hash']}</td>\n        </tr>";
    }
    echo '<table>' . "\n";
    echo $results->appends($_GET)->render();
    echo 'Current Page: ' . $results->currentPage();
    echo '<br>Items Per Page: ' . $results->perPage();
    // The following methods are only available when using the LengthAwarePaginator instance
    if ($useLengthAware) {
        echo '<br>From ' . $results->firstItem() . ' to ' . $results->lastItem();
        echo '<br>Total Items: ' . $results->total();
        echo '<br>Last Page: ' . $results->lastPage();
    }
});
$app->run();
 protected function boardListSearch($perPage = 25)
 {
     $input = $this->boardListInput();
     $title = $input['title'];
     $lang = $input['lang'];
     $page = $input['page'];
     $tags = $input['tags'];
     $sfw = $input['sfw'];
     $boards = Board::getBoardsForBoardlist();
     $boards = $boards->filter(function ($item) use($lang, $tags, $sfw, $title) {
         // Are we able to view unindexed boards?
         if (!$item->is_indexed && !$this->user->canViewUnindexedBoards()) {
             return false;
         }
         // Are we requesting SFW only?
         if ($sfw && !$item->is_worksafe) {
             return false;
         }
         // Are we searching by language?
         if ($lang) {
             $boardLang = $item->settings->where('option_name', 'boardLanguage')->pluck('option_value')->first();
             if ($lang != $boardLang) {
                 return false;
             }
         }
         // Are we searching tags?
         if ($tags && count(array_intersect($tags, $item->tags->pluck('tag')->toArray())) < count($tags)) {
             return false;
         }
         // Are we searching titles and descriptions?
         if ($title && stripos($item->board_uri, $title) === false && stripos($item->title, $title) === false && stripos($item->description, $title) === false) {
             return false;
         }
         return true;
     });
     if ($title) {
         $boards = $boards->sort(function ($a, $b) use($title) {
             // Sort by active users, then last post time.
             $aw = 0;
             $bw = 0;
             if ($a->board_uri === $title) {
                 $aw += 8;
             }
             if (stripos($a->board_uri, $title) !== false) {
                 $aw += 4;
             }
             if (stripos($a->title, $title) !== false) {
                 $aw += 2;
             }
             if (stripos($a->description, $title) !== false) {
                 $aw += 1;
             }
             if ($b->board_uri === $title) {
                 $bw += 8;
             }
             if (stripos($b->board_uri, $title) !== false) {
                 $bw += 4;
             }
             if (stripos($b->title, $title) !== false) {
                 $bw += 2;
             }
             if (stripos($b->description, $title) !== false) {
                 $bw += 1;
             }
             return $bw - $aw;
         });
     }
     $paginator = new LengthAwarePaginator($boards->forPage($page, $perPage), $boards->count(), $perPage, $page);
     $paginator->setPath("boards.html");
     foreach ($input as $inputIndex => $inputValue) {
         if ($inputIndex == "sfw") {
             $inputIndex = (int) (!!$inputValue);
         }
         $paginator->appends($inputIndex, $inputValue);
     }
     return $paginator;
 }
 /**
  * Returns Paginator Presenter object if pagination is enabled
  *
  * @param array $items
  * @return mixed
  */
 private function _getPaginatorPresenter(array $items)
 {
     if (!$this->_paginate) {
         return null;
     }
     $params = Input::get();
     if (!empty($params)) {
         // There are parameters in the URL - pass them to paginator
         if (isset($params['page'])) {
             // We don't need that - paginator will add new one
             unset($params['page']);
         }
     }
     // Prepare paginator and pass it to presenter
     $paginator = new LengthAwarePaginator($items, $this->_totalItems, $this->_perPage, $this->_page, ['path' => Request::url()]);
     $paginator->appends($params);
     return new $this->_paginationPresenter($paginator);
 }
Exemple #11
0
 /**
  * Paginator decorator .
  *
  * @param null $perPage
  * @param array $appends
  * @return mixed
  * @throws TableException
  */
 public function paginate($perPage = null, array $appends = array())
 {
     $perPage = isset($perPage) ? $perPage : $this->getPerPage();
     $data = $this->getDriver()->getData($perPage);
     $rows = $data['rows'];
     $total = $data['total'];
     $paginator = new LengthAwarePaginator($rows, $total, $perPage);
     $paginator->setPath(Paginator::resolveCurrentPath());
     $paginator->appends($appends);
     return $paginator;
 }
 public function issueEdit(Request $request)
 {
     $projects = $this->redmine->getProjects()->lists('name', 'id')->toArray();
     $users = $this->redmine->getUsers()->lists('mail', 'id')->toArray();
     $track = $this->redmine->getTrack()->lists('name', 'id')->toArray();
     $status = $this->redmine->getStatus()->lists('name', 'id')->toArray();
     $queries = $this->redmine->getQueries()->lists('name', 'id')->toArray();
     $activity = $this->redmine->getActivity()->lists('name', 'id')->toArray();
     $priority = $this->redmine->getPriority()->lists('name', 'id')->toArray();
     $per_pages = ['25' => '25', '50' => '50', '100' => '100', '200' => '200', '300' => '300'];
     $offset = ($request->input('page', 1) - 1) * $request->input('per_page', 25);
     $parmas['offset'] = $offset;
     $parmas['limit'] = $request->input('per_page', 25);
     if ($request->input('project_id')) {
         $parmas['project_id'] = $request->input('project_id');
     }
     if ($request->input('assigned_to_id')) {
         $parmas['assigned_to_id'] = $request->input('assigned_to_id');
     }
     if ($request->input('status_id')) {
         $parmas['status_id'] = $request->input('status_id');
     }
     if ($request->input('tracker_id')) {
         $parmas['tracker_id'] = $request->input('tracker_id');
     }
     if ($request->input('query_id')) {
         $parmas['query_id'] = $request->input('query_id');
     }
     $issues = $this->client->issue->all($parmas);
     if ($request->input('with_spent_hours')) {
         foreach ($issues['issues'] as $key => $issue) {
             $issues['issues'][$key]['timeentries'] = $this->client->time_entry->all(['limit' => 50, 'issue_id' => $issue['id']]);
             $issues['issues'][$key]['spent_time'] = 0;
             if (!empty($issues['issues'][$key]['timeentries']['time_entries'])) {
                 foreach ($issues['issues'][$key]['timeentries']['time_entries'] as $entry_key => $time_entry) {
                     $issues['issues'][$key]['spent_time'] = $issues['issues'][$key]['spent_time'] + $time_entry['hours'];
                 }
             }
         }
     }
     $pagination = new LengthAwarePaginator($issues['issues'], $issues['total_count'], $parmas['limit'], $request->input('page'));
     $pagination->setPath('/redmine/issues-edit');
     $paglinks = $pagination->appends($request->except(['page']))->render();
     return view('redmine.issues-edit', compact('issues', 'users', 'paglinks', 'projects', 'users', 'track', 'per_pages', 'status', 'queries', 'activity', 'priority'));
 }
Exemple #13
0
 public function acceptance(Request $req)
 {
     $perPage = 20;
     $currPage = $req->input('page', 1);
     $search = ['s' => $req->has('s') ? $req->input('s') : null, 'field' => $req->has('field') ? $req->input('field') : null];
     $data = ['title' => 'Daftar Penerimaan Material', 'asset' => new Assets(), 'js' => ['vendor/jquery.dataTables.min'], 'css' => ['jquery.dataTables'], 'position' => ['material' => 'Material', 'material/acceptance' => 'Penerimaan'], 'fetch' => Pener::fetchData(['search' => $search, 'perPage' => $perPage, 'currPage' => $currPage]), 'opened' => 'material', 'role' => $this->_user->hak_akses, 'active' => 'default', 'search' => $search, 'getNumb' => function () use($perPage, $req) {
         if ($req->has('page') && $req->input('page') != 1) {
             return $req->input('page') * $perPage - $perPage;
         } else {
             return 0;
         }
     }, 'isSelected' => function ($field) use($search) {
         if (!is_null($search['field'])) {
             if ($search['field'] == $field) {
                 return 'selected="selected"';
             }
         }
     }];
     $paginator = new LengthAwarePaginator([], $data['fetch']['total'], $perPage, $currPage);
     $paginator->setPath('acceptance');
     if ($req->has('s')) {
         $paginator->appends(['field' => $search['field'], 's' => $search['s']]);
     }
     $data['paginator'] = $paginator;
     return view('material.baseAcceptance', $data)->nest('dataListContent', 'material.acceptance.index', $data);
 }
Exemple #14
0
 /**
  * @param $collection
  * @param $perPage
  * @return LengthAwarePaginator
  */
 protected function paginateCollection($collection, $perPage)
 {
     $paginator = new LengthAwarePaginator($collection->forPage(Paginator::resolveCurrentPage(), $perPage), $collection->count(), $perPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
     $paginator->appends($this->getQueryParameters());
     return $paginator;
 }
Exemple #15
0
 protected static function performBillsPaginationQuery($config, $questionMarks, $billIds)
 {
     // Build query
     $query = "SELECT SUM(bills.final_price) AS final_price, SUM(bills.quantity) AS number_of_products, bills.id, bills.client_name, bills.campaign_order, bills.campaign_year, bills.campaign_number, bills.payment_term, bills.created_at FROM ";
     $query .= "(SELECT bill_products.final_price AS final_price, bill_products.quantity, bills.id, clients.name AS client_name, bills.campaign_order, ";
     $query .= "campaigns.year AS campaign_year, campaigns.number AS campaign_number, bills.payment_term, bills.created_at ";
     $query .= "FROM bills LEFT JOIN bill_products ON bill_products.bill_id = bills.id ";
     // Join campaigns
     $query .= "LEFT JOIN campaigns ON bills.campaign_id = campaigns.id ";
     // Join clients table
     $query .= "LEFT JOIN clients ON clients.id = bills.client_id WHERE bills.id IN ({$questionMarks}) ";
     $query .= "UNION ALL SELECT bill_application_products.final_price as final_price, bill_application_products.quantity as quantity, bills.id, ";
     $query .= "clients.name as client_name, bills.campaign_order, campaigns.year as campaign_year, campaigns.number as campaign_number, bills.payment_term, bills.created_at FROM bills ";
     // Join bill application products table
     $query .= "LEFT JOIN bill_application_products ON bill_application_products.bill_id = bills.id ";
     // Join campaigns table
     $query .= "LEFT JOIN campaigns ON campaigns.id = bills.campaign_id ";
     // Join clients table
     $query .= "LEFT JOIN clients ON clients.id = bills.client_id ";
     $query .= "WHERE bills.id IN ({$questionMarks}) AND clients.name=bills.id) bills ";
     $query .= "GROUP BY bills.id ORDER BY bills.created_at DESC";
     // Execute query
     $results = DB::select($query, $billIds);
     // Make sure page is always positive
     if ($config['page'] < 1) {
         $config['page'] = 1;
     }
     $perPage = Settings::displayedBills();
     // Calculate start from
     $startFrom = $perPage * ($config['page'] - 1);
     $sliced = array_slice($results, $startFrom, $perPage);
     $paginate = new LengthAwarePaginator($sliced, count($results), $perPage);
     if (isset($config['searchTerm']) && strlen($config['searchTerm']) > 0) {
         $paginate->setPath('/bills/get/search');
         $paginate->appends(['term' => $config['searchTerm']]);
     } else {
         $paginate->setPath('/bills/get');
     }
     return $paginate;
 }
 protected function boardListSearch($perPage = 25)
 {
     $input = $this->boardListInput();
     $title = $input['title'];
     $lang = $input['lang'];
     $page = $input['page'];
     $tags = $input['tags'];
     $sfw = $input['sfw'];
     $sort = $input['sort'];
     $sortBy = $input['sortBy'];
     $boards = collect(Board::getBoardsForBoardlist());
     $boards = $boards->filter(function ($item) use($lang, $tags, $sfw, $title) {
         // Are we able to view unindexed boards?
         if (!$item['is_indexed'] && !$this->user->canViewUnindexedBoards()) {
             return false;
         }
         // Are we requesting SFW only?
         if ($sfw && !$item['is_worksafe']) {
             return false;
         }
         // Are we searching by language?
         if ($lang) {
             $boardLang = $item->settings['boardLanguage'];
             if ($lang != $boardLang) {
                 return false;
             }
         }
         // Are we searching tags?
         if ($tags && (!count($item['tags']) || count(array_intersect($tags, array_fetch($item['tags'], 'tag'))) < count($tags))) {
             return false;
         }
         // Are we searching titles and descriptions?
         if ($title && stripos($item['board_uri'], $title) === false && stripos($item['title'], $title) === false && stripos($item['description'], $title) === false) {
             return false;
         }
         return true;
     });
     if ($title || $sort && $sortBy) {
         $sortWeight = $sortBy == "asc" ? -1 : 1;
         $boards = $boards->sort(function ($a, $b) use($title, $sort, $sortWeight) {
             // Sort by active users, then last post time.
             $aw = 0;
             $bw = 0;
             if ($title) {
                 $aw += $a['board_uri'] === $title ? 80 : 0;
                 $aw += stripos($a['board_uri'], $title) !== false ? 40 : 0;
                 $aw += stripos($a['title'], $title) !== false ? 20 : 0;
                 $aw += stripos($a['description'], $title) !== false ? 10 : 0;
                 $bw += $b['board_uri'] === $title ? 80 : 0;
                 $aw += stripos($b['board_uri'], $title) !== false ? 40 : 0;
                 $aw += stripos($b['title'], $title) !== false ? 20 : 0;
                 $aw += stripos($b['description'], $title) !== false ? 10 : 0;
             }
             if ($sort) {
                 if ($a[$sort] > $b[$sort]) {
                     $aw += $sortWeight;
                 } else {
                     if ($a[$sort] < $b[$sort]) {
                         $bw += $sortWeight;
                     }
                 }
             }
             return $bw - $aw;
         });
     }
     $paginator = new LengthAwarePaginator($boards->forPage($page, $perPage), $boards->count(), $perPage, $page);
     $paginator->setPath(url("boards.html"));
     foreach ($input as $inputIndex => $inputValue) {
         if ($inputIndex == "sfw") {
             $inputIndex = (int) (!!$inputValue);
         }
         $paginator->appends($inputIndex, $inputValue);
     }
     return $paginator;
 }
Exemple #17
0
 /**
  * Function to handle pagination requests.
  *
  * @param  EchoIt\JsonApi\Request $request
  * @param  EchoIt\JsonApi\Model $model
  * @param integer $total the total number of records
  * @return Illuminate\Pagination\LengthAwarePaginator
  */
 protected function handlePaginationRequest($request, $model, $total = null)
 {
     $page = $request->pageNumber;
     $perPage = $request->pageSize;
     if (!$total) {
         $total = $model->count();
     }
     $results = $model->forPage($page, $perPage)->get(array('*'));
     $paginator = new LengthAwarePaginator($results, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => 'page[number]']);
     $paginator->appends('page[size]', $perPage);
     if (!empty($request->filter)) {
         foreach ($request->filter as $key => $value) {
             $paginator->appends($key, $value);
         }
     }
     if (!empty($request->sort)) {
         $paginator->appends('sort', implode(',', $request->sort));
     }
     return $paginator;
 }