Пример #1
2
 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;
 }
Пример #2
0
 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);
 }
Пример #3
0
 function length_aware_paginator($items, $perPage, $currentPage = null, array $options = [])
 {
     $currentPage = $currentPage ?: LengthAwarePaginator::resolveCurrentPage();
     $startIndex = $currentPage * $perPage - $perPage;
     $paginatedItems = Collection::make($items)->slice($startIndex, $perPage);
     return new LengthAwarePaginator($paginatedItems, $items->count(), $perPage, $currentPage, ['path' => LengthAwarePaginator::resolveCurrentPath()]);
 }
Пример #4
0
 public static function getListWithPaginate($paginator = 0, $status = null, $fields = ['*'])
 {
     $query = self::select($fields);
     if ($status) {
         $query->ofStatus($status);
     }
     $freeproducts = $query->get();
     return $paginator ? new Paginator(self::getWithProducts($freeproducts), $freeproducts->count(), $paginator, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]) : self::getWithProducts($freeproducts);
 }
Пример #5
0
 public static function paginateArray($data, $perPage, $page = null)
 {
     $currentPage = LengthAwarePaginator::resolveCurrentPage();
     $pageStart = \Request::get('page', 1);
     // Start displaying items from this number;
     $offSet = $pageStart * $perPage - $perPage;
     $itemsForCurrentPage = array_slice($data, $offSet, $perPage, true);
     //$collection = collect($data);
     //$currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all();
     $paginatedSearchResults = new LengthAwarePaginator($itemsForCurrentPage, count($data), $perPage, $currentPage);
     return $paginatedSearchResults;
 }
Пример #6
0
 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]);
 }
Пример #7
0
 /**
  * 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]);
 }
Пример #8
0
 public function populars($count)
 {
     $reviews = Review::with('author', 'comments')->leftJoin('comments', 'comments.review_id', '=', 'reviews.id')->groupBy('comments.review_id')->orderBy('comment_count', 'DESC')->where('reviews.approved', '=', true)->get(['reviews.*', DB::raw('COUNT(comments.id) as comment_count')]);
     //Get current page form url e.g. &page=6
     $currentPage = LengthAwarePaginator::resolveCurrentPage();
     //Define how many items we want to be visible in each page
     $perPage = 5;
     $offset = $currentPage === "1" ? 0 : $currentPage * $perPage;
     //Create a new Laravel collection
     $collection = $reviews;
     //Slice the collection to get the items to display in current page
     $currentPageSearchResults = $collection->slice($offset, $perPage)->all();
     //Create our paginator and pass it to the view
     return new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);
     //return $reviews->paginate($count);
 }
Пример #9
0
 /**
  * Display a listing of conversations.
  *
  * @return Response
  */
 public function index()
 {
     $favorites = Favorites::where('owner_id', \Auth::id())->with('user')->orderBy('updated_at', 'DES')->take(10)->get();
     //$user
     $conversations = User::where('id', \Auth::id())->with(['conversations' => function ($query) {
         $query->with(['lastMessage', 'otherUser', 'notReadCount'])->orderBy('created_at', 'DES');
     }])->first()->conversations;
     //Get current page form url e.g. &page=6
     $currentPage = (int) LengthAwarePaginator::resolveCurrentPage();
     if (!$currentPage) {
         $currentPage = 1;
     }
     $currentPage--;
     //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
     $currentPageConversations = $conversations->slice($currentPage * $perPage, $perPage)->all();
     $conversations = new LengthAwarePaginator($currentPageConversations, count($conversations), $perPage);
     $conversations->setPath('/message');
     return view('messages', compact('conversations', 'favorites'));
 }
Пример #10
0
 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);
 }
Пример #11
0
 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]);
 }
Пример #12
0
 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'));
 }
Пример #13
0
 /**
  * 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()]);
 }
Пример #14
0
 /**
  * Search for events and shows the search screen.
  *
  * @return Response
  */
 public function scanEvents($id = null)
 {
     $events = null;
     if ($id) {
         $place = Place::where('id', $id)->first();
         $events = Event::where('date_start', '>=', new \DateTime('today'))->orderBy('date_start')->with(['places'])->get();
         foreach ($events as $event) {
             if ($place->id != '' && $event->places[0]->id == $place->id) {
                 $event->grade = 1;
             } else {
                 if ($place->state != '' && $event->places[0]->state == $place->state) {
                     $event->grade = 2;
                 } else {
                     if ($place->country != '' && $event->places[0]->country == $place->country) {
                         $event->grade = 3;
                     }
                 }
             }
         }
         $events = $events->filter(function ($event) {
             if ($event->grade) {
                 return true;
             }
         });
         $events = $events->toArray();
         // sort alphabetically by grade
         usort($events, array($this, 'compare_events'));
         $events = Collection::make($events);
         //Get current page form url e.g. &page=6
         $currentPage = (int) LengthAwarePaginator::resolveCurrentPage(1);
         if (!$currentPage) {
             $currentPage = 1;
         }
         $currentPage--;
         //Define how many items we want to be visible in each page
         $perPage = 12;
         //Slice the collection to get the items to display in current page
         $currentPageEvents = $events->slice($currentPage * $perPage, $perPage)->all();
         $events = new LengthAwarePaginator($currentPageEvents, count($events), $perPage);
         $events->setPath('/scanner/' . $id);
     }
     return view('scan', compact('events'));
 }
Пример #15
0
    public function myActivitySorting($sort_by, $id)
    {
        if (Auth::check()) {
            $title = 'mypost';
            if (Auth::user()->identifier == 1 || Auth::user()->identifier == 2) {
                $posts = Postjob::where('unique_id', '=', $id)->leftjoin('postactivities', 'postactivities.post_id', '=', 'postjobs.id');
                if ($sort_by == 'date') {
                    $posts->orderBy('postactivities.created_at', 'asc')->with('indUser', 'corpUser', 'postActivity', 'taggedUser', 'taggedGroup')->where('postjobs.individual_id', '!=', Auth::user()->induser_id)->paginate(15);
                } elseif ($sort_by == 'magic-match') {
                    $posts = Postjob::orderBy('created_at', 'asc')->with('indUser', 'corpUser', 'postActivity', 'taggedUser', 'taggedGroup')->where('individual_id', '!=', Auth::user()->induser_id)->get();
                    $posts = $posts->sortBy(function ($jobPost) {
                        return -$jobPost->magic_match;
                    });
                    $perPage = 15;
                    $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 = $posts->slice($offSet, $perPage)->all();
                    $posts = new LengthAwarePaginator($itemsForCurrentPage, count($posts), $perPage, LengthAwarePaginator::resolveCurrentPage(), array('path' => LengthAwarePaginator::resolveCurrentPath()));
                } elseif ($sort_by == 'individual') {
                    $posts = Postjob::orderByRaw(DB::raw('CASE WHEN postjobs.individual_id IS NULL THEN "corp" ELSE "ind" END DESC'))->orderBy('id', 'desc')->with('indUser', 'corpUser', 'postActivity', 'taggedUser', 'taggedGroup')->where('post_type', '=', 'job')->where('individual_id', '!=', Auth::user()->induser_id)->paginate(15);
                } elseif ($sort_by == 'corporate') {
                    $posts = Postjob::orderByRaw(DB::raw('CASE WHEN postjobs.corporate_id IS NULL THEN "ind" ELSE "corp" END ASC'))->orderBy('id', 'desc')->with('indUser', 'corpUser', 'postActivity', 'taggedUser', 'taggedGroup')->where('post_type', '=', 'job')->where('individual_id', '!=', Auth::user()->induser_id)->paginate(15);
                } else {
                    $posts = Postjob::orderBy('created_at', 'desc')->with('indUser', 'corpUser', 'postActivity', 'taggedUser', 'taggedGroup')->where('post_type', '=', 'job')->where('individual_id', '!=', Auth::user()->induser_id)->paginate(15);
                }
                $myActivities = DB::select('(select pa.id,pa.user_id,pa.post_id,"Thanks" as identifier,pa.thanks as activity, pa.thanks_dtTime as time,pj.unique_id, pj.post_title, pj.post_compname
										from postactivities pa 
										join postjobs pj on pj.id = pa.post_id
										where pa.user_id=? and pa.thanks = 1)
										union
										(select pa.id,pa.user_id,pa.post_id,"Shared" as identifier,pa.share as share, pa.share_dtTime as time,pj.unique_id, pj.post_title, pj.post_compname
										from postactivities pa 
										join postjobs pj on pj.id = pa.post_id
										where pa.user_id=? and pa.share = 1)
										union
										(select pa.id,pa.user_id,pa.post_id,"Applied" as identifier,pa.apply as activity, pa.apply_dtTime as time,pj.unique_id,pj.post_title, pj.post_compname
										from postactivities pa 
										join postjobs pj on pj.id = pa.post_id
										where pa.user_id=? and pa.apply = 1)
										union
										(select pa.id,pa.user_id,pa.post_id,"Contacted" as identifier,pa.contact_view as activity,pa.contact_view_dtTime as time,pj.unique_id, pj.post_title, pj.post_compname
										from postactivities pa 
										join postjobs pj on pj.id = pa.post_id
										where pa.user_id=? and pa.contact_view = 1)
										order by time desc', [Auth::user()->id, Auth::user()->id, Auth::user()->id, Auth::user()->id]);
                $myActivities = collect($myActivities);
                if (Auth::user()->identifier == 1) {
                    $share_links = Induser::whereRaw('indusers.id in (
													select connections.user_id as id from connections
													where connections.connection_user_id=?
													 and connections.status=1
													union 
													select connections.connection_user_id as id from connections
													where connections.user_id=?
													 and connections.status=1
										)', [Auth::user()->induser_id, Auth::user()->induser_id])->get(['id', 'fname'])->lists('fname', 'id');
                    $share_groups = Group::leftjoin('groups_users', 'groups_users.group_id', '=', 'groups.id')->where('groups.admin_id', '=', Auth::user()->induser_id)->orWhere('groups_users.user_id', '=', Auth::user()->induser_id)->groupBy('groups.id')->get(['groups.id as id', 'groups.group_name as name'])->lists('name', 'id');
                }
                return view('pages.mypost', compact('posts', 'title', 'myActivities', 'share_groups', 'share_links'));
            }
        } else {
            return redirect('login');
        }
    }
Пример #16
0
 protected function getPaginatedIfNeeded(NotifynderCollection $notifications, $perPage, $paginate)
 {
     if (!$this->isPaginated($paginate)) {
         return $notifications->parse();
     } elseif ($paginate === true) {
         $paginate = null;
     }
     $page = LengthAwarePaginator::resolveCurrentPage();
     $total = $notifications->count();
     $notifications = $notifications->forPage($page, $perPage);
     return new LengthAwarePaginator($notifications->parse(), $total, $perPage, $paginate, ['path' => LengthAwarePaginator::resolveCurrentPath()]);
 }