public function getInitial() { $words = new Collection(explode(' ', $this->name)); // if name contains single word, use first N character if ($words->count() === 1) { if ($this->name->length() >= $this->length) { return $this->name->substr(0, $this->length); } return (string) $words->first(); } // otherwise, use initial char from each word $initials = new Collection(); $words->each(function ($word) use($initials) { $initials->push(Stringy::create($word)->substr(0, 1)); }); return $initials->slice(0, $this->length)->implode(''); }
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; }
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); }
protected function internalMake(Collection $columns, array $searchColumns = array()) { $this->compileArray($columns); $this->doInternalSearch($columns, $searchColumns); $this->doInternalOrder(); return $this->workingCollection->slice($this->skip, $this->limit); }
public function characters(Request $request) { $characters = Cache::get('characters'); $current_page = LengthAwarePaginator::resolveCurrentPage(); if (is_null($current_page)) { $current_page = 1; } $characters_collection = new Collection($characters); $items_per_page = 8; $current_page_results = $characters_collection->slice(($current_page - 1) * $items_per_page, $items_per_page)->all(); $paginated_results = new LengthAwarePaginator($current_page_results, count($characters_collection), $items_per_page); return view('characters', ['paginated_results' => $paginated_results, 'characters' => $characters]); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { FlashPlayerSession::Flash(); $players = $teams = Auth::user()->players(); $currentPage = LengthAwarePaginator::resolveCurrentPage(); //Create a new Laravel collection from the array data $collection = new Collection($players); //Define how many items we want to be visible in each page $perPage = 10; //Slice the collection to get the items to display in current page $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all(); //Create our paginator and pass it to the view $paginatedSearchResults = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage); return view('frontend.ball.player.index', ['players' => $paginatedSearchResults]); }
/** * 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; }
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 characters(Request $request) { $search_term = ''; if ($request->has('query')) { $search_term = $request->input('query'); $query = $this->client->getConfig('query'); $query['nameStartsWith'] = $search_term; $response = $this->client->get('characters', ['query' => $query]); $response = json_decode($response->getBody(), true); $characters = $response['data']['results']; } else { $characters = Cache::get('characters'); } $current_page = LengthAwarePaginator::resolveCurrentPage(); if (is_null($current_page)) { $current_page = 1; } $characters_collection = new Collection($characters); $items_per_page = 8; $current_page_results = $characters_collection->slice(($current_page - 1) * $items_per_page, $items_per_page)->all(); $paginated_results = new LengthAwarePaginator($current_page_results, count($characters_collection), $items_per_page); return view('characters', ['paginated_results' => $paginated_results, 'characters' => $characters, 'query' => $search_term]); }
/** * Perform pagination * * @return mixed */ public function paging() { $this->collection = $this->collection->slice($this->request->getStart(), $this->request->getCount()); }
/** * @inheritdoc */ public function paging() { $this->collection = $this->collection->slice($this->request['start'], (int) $this->request['length'] > 0 ? $this->request['length'] : 10); }
/** * @param $fs Filesystem * @param $scrapers Collection **/ protected function processChunk(Filesystem $fs, Collection $scrapers) { $lastJob = 0; if ($fs->exists('lastScraperRun')) { $lastJob = $fs->get('lastScraperRun'); } $scrapers->slice($lastJob, self::JOBS_PER_CALL); $this->scheduleScrapers($scrapers); $nextJob = 0; if ($lastJob + self::JOBS_PER_CALL > $scrapers->count()) { $nextJob = $lastJob + self::JOBS_PER_CALL; } $fs->put('lastScraperRun', $nextJob); }
public function search() { session_start(); unset($_SESSION['contact_report_to']); //create a session for location $_SESSION['loc'] = "ticket"; //creating objects $pagesettings = new functions\pagesettings(); //get selected columns $selected_columns = $pagesettings->fname('ticket', '1'); //get select columns names foreach ($selected_columns as $result) { $column_comment = $pagesettings->viewcolumncomment($result->column_name, 'ticket'); foreach ($column_comment as $result_2) { $table_headings[] = $result_2->column_comment; } } $_SESSION['sort'] = "DESC"; //get data for call log $result = $this->view_tickets_all(1000, 0); //Get current page form url e.g. &page=6 $currentPage = LengthAwarePaginator::resolveCurrentPage(); //pagination starting form 0. e.g. &page=1 mean page=0 if ($currentPage != NULL) { $currentPage = $currentPage - 1; } //Create a new Laravel collection from the array data $collection = new Collection($result); //Define how many items we want to be visible in each page $perPage = 1000000; //Slice the collection to get the items to display in current page $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all(); //Create our paginator and pass it to the view $result = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage); //return this data to the view return View::make('ticket.ticket', compact('table_headings', 'selected_columns', 'result')); }
/** * @inheritdoc */ protected function paginate() { $this->collection = $this->collection->slice($this->input['start'], (int) $this->input['length'] > 0 ? $this->input['length'] : 10); }
/** * Paginate a set of record results * * @param $records the set of records * @param $perPage number of records to show per page * @param $request the request object * * @return the LengthAwarePaginator object */ protected function paginateResults($records, $perPage, $request) { //Get current page form url e.g. &page=6 $currentPage = LengthAwarePaginator::resolveCurrentPage(); //Create a new Laravel collection from the array data $collection = new Collection($records); //Slice the collection to get the items to display in current page $currentPageSearchResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->all(); //Create the paginator return new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage, $currentPage, ['path' => $request->url(), 'query' => $request->query()]); }
public function testSliceNegativeOffsetAndNegativeLength() { $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]); $this->assertEquals([3, 4, 5, 6], $collection->slice(-6, -2)->values()->toArray()); }
public function getItems($requestedLimit, $requestedOffset) { $items = $this->collection->slice($requestedOffset, $requestedLimit); return [$items, $this->collection->count()]; }