/** * Register the service provider. * * @return void */ public function register() { $this->app['paginator'] = $this->app->share(function ($app) { $paginator = new Environment($app['request'], $app['view'], $app['translator']); $paginator->setViewName($app['config']['view.pagination']); return $paginator; }); }
/** * Register the service provider. * * @return void */ public function register() { $this->app->bindShared('paginator', function ($app) { $paginator = new Environment($app['request'], $app['view'], $app['translator']); $paginator->setViewName($app['config']['view.pagination']); $app->refresh('request', $paginator, 'setRequest'); return $paginator; }); }
/** * Paginate the collection. * * @param int $perPage * @return \Illuminate\Pagination\Paginator */ public function paginate($perPage = 5) { $totalPages = ceil(count($this->items) / $perPage); // Get the page and make sure that the page hasn't been tampered with. If the page is // out of bounds then we'll default to the last page or the first page. $page = $this->request->query('page', 1); if ($page > $totalPages) { $page = $totalPages; } elseif ($page < 1) { $page = 1; } $articles = array_slice($this->items, ($page - 1) * $perPage, $perPage); return $this->paginator->make($articles, count($this->items), $perPage); }
/** * Get a paginator for an ungrouped statement. * * @param \Illuminate\Pagination\Environment $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator */ protected function ungroupedPaginate($paginator, $perPage, $columns) { $total = $this->query->getPaginationCount(); // Once we have the paginator we need to set the limit and offset values for // the query so we can get the properly paginated items. Once we have an // array of items we can create the paginator instances for the items. $page = $paginator->getCurrentPage($total); $this->query->forPage($page, $perPage); return $paginator->make($this->get($columns)->all(), $total, $perPage); }
/** * Create a paginator for an un-grouped pagination statement. * * @param \Illuminate\Pagination\Environment $paginator * @param int $perPage * @param array $columns * @return \Illuminate\Pagination\Paginator */ protected function ungroupedPaginate($paginator, $perPage, $columns) { $total = $this->getPaginationCount(); // Once we have the total number of records to be paginated, we can grab the // current page and the result array. Then we are ready to create a brand // new Paginator instances for the results which will create the links. $page = $paginator->getCurrentPage($total); $results = $this->forPage($page, $perPage)->get($columns); return $paginator->make($results, $total, $perPage); }
/** * Set the base URL in use by the paginator. * * @param string $baseUrl * @return void */ public function setBaseUrl($baseUrl) { $this->env->setBaseUrl($baseUrl); }
/** * Get the translator instance. * * @return \Symfony\Component\Translation\TranslatorInterface * @static */ public static function getTranslator() { return \Illuminate\Pagination\Environment::getTranslator(); }
$filters['after'] = explode('|', $filters['after']); } } else { $filters['after'] = array(); } Route::group(array('before' => $filters['before'], 'after' => $filters['after']), function () { Route::get(Config::get('logviewer::base_url') . '/{path}/{sapi}/{date}/{level?}', function ($path, $sapi, $date, $level = null) { if (is_null($level) || !is_string($level)) { $level = 'all'; } $logviewer = new Logviewer($path, $sapi, $date, $level); $log = $logviewer->log(); $levels = $logviewer->getLevels(); // PHP 5.3 does not support $this in closure scope // SEE: https://wiki.php.net/rfc/closures/removal-of-this //$paginator = new Environment($this->app['request'], $this->app['view'], $this->app['translator']); $paginator = new Environment(App::make('request'), App::make('view'), App::make('translator')); $view = Config::get('logviewer::p_view'); if (is_null($view) || !is_string($view)) { $view = Config::get('view.pagination'); } $paginator->setViewName($view); $per_page = Config::get('logviewer::per_page'); if (is_null($per_page) || !is_int($per_page)) { $per_page = 10; } $page = $paginator->make($log, count($log), $per_page); return View::make(Config::get('logviewer::view'))->with('paginator', $page)->with('log', count($log) > $page->getPerPage() ? array_slice($log, $page->getFrom() - 1, $page->getPerPage()) : $log)->with('empty', $logviewer->isEmpty())->with('date', $date)->with('sapi', Lang::get('logviewer::logviewer.sapi.' . $sapi))->with('sapi_plain', $sapi)->with('url', Config::get('logviewer::base_url'))->with('levels', $levels)->with('path', $path); }); }); });