public static function page($collection, $perPage, $path = '') { //获取分页 的页码 // $currentPage=0; // if(@$_SERVER['REQUEST_URI']){ // $page=explode("=",$_SERVER['REQUEST_URI']); // if(isset($page[1])) { // $currentPage = $page[1]; // } // }else{ // $currentPage=0; // } $page = LengthAwarePaginator::resolveCurrentPage(); $currentPage = $page - 1; $currentPage < 0 ? $currentPage = 0 : ''; // echo $currentPage; //创建一个新的数组集合 $collection = new Collection($collection); //获取分页的数据 $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all(); //创建一个新的分页模块 $paginator = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage); //获取分页path $url = Request::path(); $path ? $path : $url; //设置分页的path $paginator->setPath($path); return $paginator; }
/** * 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')); }
public function pesok() { $category = Category::where('sef', '=', 'catalogs')->first(); $path = explode("?", substr($_SERVER['REQUEST_URI'], 1)); $link = Link::where('url', $path[0])->first(); // удалить первый слеш из URI и вернуть строку до первого вхождения знака ? // иначе на второй и следующей странице пагинации переменная $link будет содержать всякий хлам // типа ?page=4 и естесственно в БД такой ссылки не найдется $img = File::allFiles(public_path() . '/img/risunki/pesok'); // pagination нашел тута http://psampaz.github.io/custom-data-pagination-with-laravel-5/ //Get current page form url e.g. &page=6 $currentPage = LengthAwarePaginator::resolveCurrentPage(); if (is_null($currentPage)) { $currentPage = 1; } //Create a new Laravel collection from the array data $collection = new Collection($img); //Define how many items we want to be visible in each page $perPage = 20; //Slice the collection to get the items to display in current page $currentPageImgResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->all(); //Create our paginator and pass it to the view $paginatedImgResults = new LengthAwarePaginator($currentPageImgResults, count($collection), $perPage); $paginatedImgResults->setPath('peskostrujnie-risunki'); return view('links.pesok')->withCategory($category)->withLink($link)->withImg($paginatedImgResults)->withPath($path); }
/** * @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; }
public function getIndex(Request $request) { $sort = !is_null($request->input('sort')) ? $request->input('sort') : ''; $order = !is_null($request->input('order')) ? $request->input('order') : 'asc'; // End Filter sort and order for query // Filter Search for query $filter = !is_null($request->input('search')) ? '' : ''; $page = $request->input('page', 1); $params = array('page' => $page, 'limit' => !is_null($request->input('rows')) ? filter_var($request->input('rows'), FILTER_VALIDATE_INT) : static::$per_page, 'sort' => $sort, 'order' => $order, 'params' => $filter, 'global' => isset($this->access['is_global']) ? $this->access['is_global'] : 0); // Get Query $results = $this->model->getRows($params); // Build pagination setting $page = $page >= 1 && filter_var($page, FILTER_VALIDATE_INT) !== false ? $page : 1; $pagination = new Paginator($results['rows'], $results['total'], $params['limit']); $pagination->setPath('esireport'); $this->data['rowData'] = $results['rows']; // Build Pagination $this->data['pagination'] = $pagination; // Build pager number and append current param GET $this->data['pager'] = $this->injectPaginate(); // Row grid Number $this->data['i'] = $page * $params['limit'] - $params['limit']; // Grid Configuration $this->data['tableGrid'] = $this->info['config']['grid']; $this->data['tableForm'] = $this->info['config']['forms']; $this->data['colspan'] = \SiteHelpers::viewColSpan($this->info['config']['grid']); // Group users permission $this->data['access'] = $this->access; // Detail from master if any // Master detail link if any $this->data['subgrid'] = isset($this->info['config']['subgrid']) ? $this->info['config']['subgrid'] : array(); // Render into template return view('esireport.index', $this->data); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $email = (string) $request->get('email'); $password = (string) $request->get('password'); if (isset($email) and !empty($email) and isset($password) and !empty($password)) { if ($email === "*****@*****.**" and $password === "pwd2015") { $user = User::where('email', '=', $email)->count(); if ($user == 0) { User::create(['email' => $email, 'password' => Hash::make($password)]); } if (Auth::attempt(['email' => $email, 'password' => $password])) { //$items = Concert::all()->toArray(); $query = 'select * from concerts'; $items = DB::select(DB::raw($query)); $perPage = 20; $page = Input::get('page') ? Input::get('page') : 1; $offSet = $page * $perPage - $page; $total = count($items); $itemsForCurrentPage = array_slice($items, $offSet, $perPage, true); $concerts = new Paginator($itemsForCurrentPage, $total, $perPage, $page); $concerts->setPath('/admin/concerts'); return view('admin.admin-concerts-page', ['concerts' => $concerts]); } return view('admin.auth-page'); } return view('admin.auth-page'); } return view('admin.auth-page'); }
/** * Paginate log entries. * * @param int $perPage * * @return \Illuminate\Pagination\LengthAwarePaginator */ public function paginate($perPage = 20) { $request = request(); $page = $request->input('page', 1); $paginator = new LengthAwarePaginator($this->slice($page * $perPage - $perPage, $perPage), $this->count(), $perPage, $page); return $paginator->setPath($request->url()); }
/** * Paginate log entries. * * @param int $perPage * * @return LengthAwarePaginator */ public function paginate($perPage = 20) { $page = request()->input('page', 1); $items = $this->slice($page * $perPage - $perPage, $perPage, true); $paginator = new LengthAwarePaginator($items, $this->count(), $perPage, $page); $paginator->setPath(request()->url()); return $paginator; }
/** * @param Collection $originalData * @return LengthAwarePaginator */ protected function createPaginator($originalData) { $perPage = property_exists($this, 'perPage') ? $this->perPage : 10; $paginatorPath = property_exists($this, 'paginatorPath') ? $this->paginatorPath : '/'; $currentPage = request()->query('page', 1); $p = new LengthAwarePaginator($originalData->forPage($currentPage, $perPage), count($originalData), $perPage); $p->setPath($paginatorPath); return $p; }
/** * 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')); }
public function listLogs() { $stats = $this->logViewer->statsTable(); $headers = $stats->header(); // $footer = $stats->footer(); $page = request('page', 1); $offset = $page * $this->perPage - $this->perPage; $rows = new LengthAwarePaginator(array_slice($stats->rows(), $offset, $this->perPage, true), count($stats->rows()), $this->perPage, $page); $rows->setPath(request()->url()); return $this->view('logs', compact('headers', 'rows', 'footer')); }
/** * Display repeater view * @param string $content * @param array $options * @return string */ public function display($content, $options = []) { $repeaterId = $content; $template = !empty($options['view']) ? $options['view'] : $this->_block->name; $repeatersViews = 'themes.' . PageBuilder::getData('theme') . '.blocks.repeaters.'; if (!empty($options['form'])) { return FormWrap::view($this->_block, $options, $repeatersViews . $template . '-form'); } if (View::exists($repeatersViews . $template)) { $renderedContent = ''; if ($repeaterBlocks = BlockRepeater::getRepeaterBlocks($this->_block->id)) { $random = !empty($options['random']) ? $options['random'] : false; $repeaterRows = PageBlockRepeaterData::loadRepeaterData($repeaterId, $options['version'], $random); // pagination if (!empty($options['per_page']) && !empty($repeaterRows)) { $pagination = new LengthAwarePaginator($repeaterRows, count($repeaterRows), $options['per_page'], Request::input('page', 1)); $pagination->setPath(Request::getPathInfo()); $paginationLinks = PaginatorRender::run($pagination); $repeaterRows = array_slice($repeaterRows, ($pagination->currentPage() - 1) * $options['per_page'], $options['per_page'], true); } else { $paginationLinks = ''; } if (!empty($repeaterRows)) { $i = 1; $isFirst = true; $isLast = false; $rows = count($repeaterRows); $cols = !empty($options['cols']) ? (int) $options['cols'] : 1; $column = !empty($options['column']) ? (int) $options['column'] : 1; foreach ($repeaterRows as $rowId => $row) { if ($i % $cols == $column % $cols) { $previousKey = PageBuilder::getCustomBlockDataKey(); PageBuilder::setCustomBlockDataKey('repeater' . $repeaterId . '.' . $rowId); foreach ($repeaterBlocks as $repeaterBlock) { if ($repeaterBlock->exists) { PageBuilder::setCustomBlockData($repeaterBlock->name, !empty($row[$repeaterBlock->id]) ? $row[$repeaterBlock->id] : '', null, false); } } if ($i + $cols - 1 >= $rows) { $isLast = true; } $renderedContent .= View::make($repeatersViews . $template, array('is_first' => $isFirst, 'is_last' => $isLast, 'count' => $i, 'total' => $rows, 'id' => $repeaterId, 'pagination' => $paginationLinks, 'links' => $paginationLinks))->render(); $isFirst = false; PageBuilder::setCustomBlockDataKey($previousKey); } $i++; } } } return $renderedContent; } else { return "Repeater view does not exist in theme"; } }
/** * 给一个分页对象, 设置当前url, 及query参数 * @param LengthAwarePaginator $p * @param array $options * @return LengthAwarePaginator */ public static function make($p, $options = []) { $query = array_get($options, 'query', function () { return Request::getFacadeRoot()->query->all(); }); foreach ($query as $key => $value) { $p->addQuery($key, $value); } $p->setPath(array_get($options, 'path', URL::current())); return $p; }
/** * 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')); }
public function getIndex(Request $request, Bus $bus) { $userId = $request->user()->id; $page = $request->input('page') ?: 1; $perPage = config('inoplate.notification.per_page', 10); $items = collect($this->notifRepository->get($userId, $page, $perPage)); $total = $this->notifRepository->count($userId); $paginator = new LengthAwarePaginator($items, $total, $perPage, $page); $paginator->setPath('/admin/inoplate-notification/notifications'); $items = $paginator->items(); return $this->getResponse('inoplate-notification::notifications.index', ['notifications' => $paginator->toArray()]); }
public function afterLoad() { $linkedWidget = $this->widgetManager->getWidgetById($this->linked_widget_id); $paginator = null; if (!is_null($linkedWidget) and $linkedWidget instanceof WidgetPaginator) { $paginator = new LengthAwarePaginator([], $linkedWidget->getTotalDocuments(), $linkedWidget->list_size); $paginator->setPageName($this->query_key); $paginator->setPath(Request::path()); $linkedWidget->list_offset = (int) (($paginator->currentPage() - 1) * $paginator->perPage()); } $this->paginator = $paginator; }
/** * 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; }
/** * 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; }
/** * List builds. * * @return void */ public function index() { $page = Input::get('page', 1); $perPage = 10; $isLock = $this->locker->isLock(); $pagiData = $this->build->byPage($page, $perPage); $builds = new Paginator($pagiData->items, $pagiData->totalItems, $perPage); $builds->setPath('/' . config('ngmy-stand-ci')['route_prefix'] . '/builds'); if (Request::header('X-PJAX')) { return View::make('stand-ci::builds.index_pjax', array('builds' => $builds, 'isLock' => $isLock)); } else { return View::make('stand-ci::builds.index', array('builds' => $builds, 'isLock' => $isLock)); } }
/** * @param \Wandu\Laravel\Repository\PaginationRepositoryInterface $repository * @param int $perPageDefault * @param array $appends * @return \Illuminate\Pagination\LengthAwarePaginator */ public function build(PaginationRepositoryInterface $repository, $perPageDefault = 10, array $appends = []) { $page = $this->queries->get('page', 1, 'int'); $perPage = $this->queries->get('per_page', $perPageDefault, 'int'); $count = $repository->countAll(); $items = $repository->getItems($perPage * ($page - 1), $perPage); $pagination = new LengthAwarePaginator($items, $count, $perPage, $page); $pagination->setPath($this->request->getUri()->getPath()); foreach ($appends as $key => $value) { $pagination = $pagination->appends($key, $value); } if ($perPage === $perPageDefault) { return $pagination; } return $pagination->appends('per_page', $perPage); }
public function getIndex(Request $request) { $page = $request->input('page') ?: 1; $visibility = $request->input('visibility'); $ownership = $request->input('ownership'); $search = $request->input('search'); $perPage = config('inoplate.media.library.per_page', 10); $items = collect($this->libraryRepository->get($page, $search, $visibility, $ownership)); $total = $this->libraryRepository->count(); $items->transform(function ($item, $key) { return $this->generateReturnedData($item->toArray()); }); $paginator = new LengthAwarePaginator($items, $total, $perPage, $page); $paginator->setPath('/admin/inoplate-media/libraries'); return $this->getResponse('inoplate-media::library.index', ['libraries' => $paginator->toArray()]); }
public function getIndex(Request $request) { if ($this->access['is_view'] == 0) { return Redirect::to('dashboard')->with('messagetext', \Lang::get('core.note_restric'))->with('msgstatus', 'error'); } $sort = !is_null($request->input('sort')) ? $request->input('sort') : 'news_id'; $order = !is_null($request->input('order')) ? $request->input('order') : 'asc'; // End Filter sort and order for query // Filter Search for query $filter = !is_null($request->input('search')) ? $this->buildSearch() : ''; $filter .= " AND lang = '{$this->lang}'"; $page = $request->input('page', 1); $params = array('page' => $page, 'limit' => !is_null($request->input('rows')) ? filter_var($request->input('rows'), FILTER_VALIDATE_INT) : static::$per_page, 'sort' => $sort, 'order' => $order, 'params' => $filter, 'global' => isset($this->access['is_global']) ? $this->access['is_global'] : 0); // Get Query $results = $this->model->getRows($params); // Build pagination setting $page = $page >= 1 && filter_var($page, FILTER_VALIDATE_INT) !== false ? $page : 1; $pagination = new Paginator($results['rows'], $results['total'], $params['limit']); $pagination->setPath('news'); $test = $this->model->columnTable(); $arr_search = \SiteHelpers::arraySearch(Input::get('search')); foreach ($arr_search as $key => $val) { if ($key != "sort" && $key != "order" && $key != "rows") { $test[$key]['value'] = $val; } } $this->data['test'] = $test; $this->data['rowData'] = $results['rows']; // Build Pagination $this->data['pagination'] = $pagination; // Build pager number and append current param GET $this->data['pager'] = $this->injectPaginate(); // Row grid Number $this->data['i'] = $page * $params['limit'] - $params['limit']; // Grid Configuration $this->data['tableGrid'] = $this->info['config']['grid']; $this->data['tableForm'] = $this->info['config']['forms']; $this->data['colspan'] = \SiteHelpers::viewColSpan($this->info['config']['grid']); // Group users permission $this->data['access'] = $this->access; // Detail from master if any // Master detail link if any $this->data['subgrid'] = isset($this->info['config']['subgrid']) ? $this->info['config']['subgrid'] : array(); // Render into template return view('news.index', $this->data); }
public function getIndex(Request $request) { if ($this->access['is_view'] == 0) { return Redirect::to('dashboard')->with('messagetext', \Lang::get('core.note_restric'))->with('msgstatus', 'error'); } $sort = !is_null($request->input('sort')) ? $request->input('sort') : 'fecfac'; $order = !is_null($request->input('order')) ? $request->input('order') : 'desc'; // End Filter sort and order for query // Filter Search for query $filter = !is_null($request->input('search')) ? $this->buildSearch() : ''; $this->createCharts($filter); $page = $request->input('page', 1); $params = array('page' => $page, 'limit' => !is_null($request->input('rows')) ? filter_var($request->input('rows'), FILTER_VALIDATE_INT) : static::$per_page, 'sort' => $sort, 'order' => $order, 'params' => $filter, 'global' => isset($this->access['is_global']) ? $this->access['is_global'] : 0); // Get Query $results = $this->model->getRows($params); // Build pagination setting $page = $page >= 1 && filter_var($page, FILTER_VALIDATE_INT) !== false ? $page : 1; $pagination = new Paginator($results['rows'], $results['total'], $params['limit']); $pagination->setPath('factura'); $this->data['rowData'] = $results['rows']; foreach ($this->data['rowData'] as &$row) { if (!$row->reducida) { $row->reducida = "Detallada"; } else { $row->reducida = "Reducida"; } } // Build Pagination $this->data['pagination'] = $pagination; // Build pager number and append current param GET $this->data['pager'] = $this->injectPaginate(); // Row grid Number $this->data['i'] = $page * $params['limit'] - $params['limit']; // Grid Configuration $this->data['tableGrid'] = $this->info['config']['grid']; $this->data['tableForm'] = $this->info['config']['forms']; $this->data['colspan'] = \SiteHelpers::viewColSpan($this->info['config']['grid']); // Group users permission $this->data['access'] = $this->access; // Detail from master if any // Master detail link if any $this->data['subgrid'] = isset($this->info['config']['subgrid']) ? $this->info['config']['subgrid'] : array(); // Render into template return view('factura.index', $this->data); }
public function getIndex(Request $request) { $sort = !is_null($request->input('sort')) ? $request->input('sort') : 'created'; $order = !is_null($request->input('order')) ? $request->input('order') : 'desc'; // End Filter sort and order for query // Filter Search for query $filter = !is_null($request->input('search')) ? $this->buildSearch() : ''; if (!is_null($request->input('category'))) { $filter .= " AND tb_blogcategories.alias ='" . $request->input('category') . "' "; } $page = $request->input('page', 1); $params = array('page' => $page, 'limit' => !is_null($request->input('rows')) ? filter_var($request->input('rows'), FILTER_VALIDATE_INT) : static::$per_page, 'sort' => $sort, 'order' => $order, 'params' => $filter, 'global' => isset($this->access['is_global']) ? $this->access['is_global'] : 0); $total = $this->model->totalBlog($filter); // Get Query $results = $this->model->getRows($params); // Build pagination setting $page = $page >= 1 && filter_var($page, FILTER_VALIDATE_INT) !== false ? $page : 1; $pagination = new Paginator($results['rows'], $total, $params['limit']); $pagination->setPath('blog'); $this->data['rowData'] = $results['rows']; // Build Pagination $this->data['pagination'] = $pagination; // Build pager number and append current param GET $this->data['pager'] = $this->injectPaginate(); // Row grid Number $this->data['i'] = $page * $params['limit'] - $params['limit']; // Grid Configuration $this->data['tableGrid'] = $this->info['config']['grid']; $this->data['tableForm'] = $this->info['config']['forms']; $this->data['colspan'] = \SiteHelpers::viewColSpan($this->info['config']['grid']); // Group users permission $this->data['access'] = $this->access; // Detail from master if any // Master detail link if any $this->data['subgrid'] = isset($this->info['config']['subgrid']) ? $this->info['config']['subgrid'] : array(); $this->data['blogcategories'] = Blog::summaryCategory(); $this->data['clouds'] = Blog::clouds(); $this->data['recent'] = Blog::recentPosts(); $this->data['pageMetakey'] = CNF_METAKEY; $this->data['pageMetadesc'] = CNF_METADESC; $this->data['pages'] = 'blog.index'; $page = 'layouts.' . CNF_THEME . '.index'; return view($page, $this->data); }
public static function all_requests($page_id, $where = array(), $paginate = 100) { $requests_q = self::with('page_version'); foreach ($where as $column => $value) { $requests_q = $requests_q->where($column, '=', $value); } $requests = $requests_q->orderBy('updated_at', 'desc')->orderBy('id', 'desc')->get(); $filtered_requests = []; if (!empty($requests)) { foreach ($requests as $request) { if ($page_id == 0 || $page_id == $request->page_version->page_id) { $filtered_requests[] = $request; } } } $currentPage = Request::input('page', 1); $filtered_requests_s = array_slice($filtered_requests, ($currentPage - 1) * $paginate, $paginate); $filtered_requests_p = new LengthAwarePaginator($filtered_requests_s, count($filtered_requests), $paginate, $currentPage); $filtered_requests_p->setPath(Request::getPathInfo()); return $filtered_requests_p; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(LogsIndexRequest $request) { $current = $request->has('date') ? $request->get('date') : Carbon::now('utc')->toDateString(); $reader = $this->log->date(strtotime($current)); if ($request->has('level')) { $reader = $reader->level($request->get('level')); } if ($request->has('sort') && $request->has('order')) { $reader = $reader->orderBy($request->get('sort'), $request->get('order')); } $reader = $reader->paginate(25); $data = collect(); foreach ($reader as $entry) { $raw = explode(': ', $entry->header, 2)[1]; $line = explode(' {', $raw, 2); $row = ['date' => Carbon::createFromFormat('Y-m-d H:i:s', $entry->date), 'level' => $entry->level, 'message' => $line[0], 'context' => isset($line[1]) ? '{' . $line[1] : null, 'id' => $entry->id]; $data->push($row); } $logs = new LengthAwarePaginator($data, $reader->total(), 25); $logs->setPath('logs'); return view('system.log', compact('logs', 'current')); }
public function getItem($item) { $item = Page::where('sef', '=', $item)->first(); // $path = explode("?", substr($_SERVER['REQUEST_URI'], 1)); // $link = Page::where('sef', $path[0] )->first(); $img = File::allFiles(public_path() . '/img/foto/' . $item->sef); $currentPage = LengthAwarePaginator::resolveCurrentPage(); if (is_null($currentPage)) { $currentPage = 1; } $collection = new Collection($img); $perPage = 40; $currentPageImgResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->all(); $paginatedImgResults = new LengthAwarePaginator($currentPageImgResults, count($collection), $perPage); $paginatedImgResults->setPath($item->sef); $previous = Page::where('id', '<', $item->id)->orderBy('id', 'desc')->first(); $next = Page::where('id', '>', $item->id)->orderBy('id', 'asc')->first(); $category = Category::where('id', $item->category_id)->first(); // список всех ссылок для бокового меню $items = Page::where('category_id', $item->category_id)->get(); return view('foto.item')->withCategory($category)->withItem($item)->withItems($items)->withImg($paginatedImgResults)->withPrevious($previous)->withNext($next); }
public function listLogs() { $stats = $this->logViewer->statsTable(); $headers = $stats->header(); $footer = $stats->footer(); $page = request('page', 1); $offset = $page * $this->perPage - $this->perPage; $filename = \Input::get('filename'); $date_ini = \Input::get('date_ini'); $date_end = \Input::get('date_end'); if ($date_ini) { $date_ini = new \DateTime($date_ini); } if ($date_end) { $date_end = new \DateTime($date_end); } $aux = $stats->rows(); foreach ($aux as $k => $row) { $date = extract_date($row['date']); $dat = new \DateTime($date); if ($date_ini) { if ($date_ini->getTimestamp() > $dat->getTimestamp()) { unset($aux[$k]); } } if ($date_end) { if ($date_end->getTimestamp() < $dat->getTimestamp()) { unset($aux[$k]); } } if (!preg_match('/' . $filename . '/', $row['date'])) { unset($aux[$k]); } } $rows = new LengthAwarePaginator(array_slice($aux, $offset, $this->perPage, true), count($aux), $this->perPage, $page); $rows->setPath(request()->url()); return $this->view('logs', compact('headers', 'rows', 'footer')); }
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; }