示例#1
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()]);
 }
 /**
  * Show a list of all contacts
  *
  * @return View
  */
 public function getIndex()
 {
     // Title
     $title = 'Boite de réception';
     try {
         $page = Input::get('page', 1);
         $limit = Input::get('limit', 10);
         $sortBy = Input::get('sortBy', 'created_at');
         $sortDirection = Input::get('sortDirection', 'desc');
         $data = $this->model->getByPage($page, $limit, $sortBy, $sortDirection, []);
         $totalItems = $data->totalItems;
         $limit = $data->limit;
         $models = new Paginator($data->items, $data->totalItems, $data->limit, $page, ['path' => Paginator::resolveCurrentPath()]);
     } catch (RequestException $e) {
         echo $e->getRequest() . "\n";
         if ($e->hasResponse()) {
             echo $e->getResponse() . "\n";
         }
         exit;
     }
     JavaScript::put(['locale' => LaravelLocalization::setLocale(), 'collection' => $models->getcollection()->toJson()]);
     $data = array('title' => $title, 'models' => $models, 'modelBreacrumbs' => '', 'totalItems' => $totalItems, 'limit' => $limit, 'sortBy' => $sortBy, 'sortDirection' => $sortDirection, 'routes' => array('create' => 'admin/contacts/create', 'export' => 'admin/contacts/export'));
     // Show the page
     return View::make('admin.index', $data);
 }
示例#3
0
 /**
  * PlasticPaginator constructor.
  *
  * @param PlasticResult $result
  * @param int           $limit
  * @param int           $page
  */
 public function __construct(PlasticResult $result, $limit, $page)
 {
     $this->result = $result;
     parent::__construct($result->hits(), $result->totalHits(), $limit, $page, ['path' => LengthAwarePaginator::resolveCurrentPath()]);
     $hitsReference =& $this->items;
     $result->setHits($hitsReference);
 }
示例#4
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Support\Facades\Response
  */
 public function index()
 {
     $page = Input::get('page');
     $perPage = config('typicms.news.per_page');
     $data = $this->repository->byPage($page, $perPage, ['translations']);
     $models = new Paginator($data->items, $data->totalItems, $perPage, null, ['path' => Paginator::resolveCurrentPath()]);
     return view('news::public.index')->with(compact('models'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\View\View
  */
 public function index()
 {
     $page = Request::input('page');
     $perPage = config('typicms.galleries.per_page');
     $data = $this->repository->byPage($page, $perPage, []);
     $models = new Paginator($data->items, $data->totalItems, $perPage, null, ['path' => Paginator::resolveCurrentPath()]);
     return view('galleries::public.index')->with(compact('models'));
 }
示例#6
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);
 }
 /**
  * List files.
  *
  * @return \Illuminate\View\View
  */
 public function index()
 {
     $page = Request::input('page');
     $type = Request::input('type');
     $gallery_id = Request::input('gallery_id');
     $view = Request::input('view');
     if ($view != 'filepicker') {
         $view = 'index';
         $models = $this->repository->all([], true);
         app('JavaScript')->put('models', $models);
     } else {
         $perPage = config('typicms.files.per_page');
         $data = $this->repository->byPageFrom($page, $perPage, $gallery_id, [], true, $type);
         $models = new Paginator($data->items, $data->totalItems, $perPage, null, ['path' => Paginator::resolveCurrentPath()]);
     }
     return view('files::admin.' . $view)->with(compact('models'));
 }
示例#8
0
 /**
  * Return Laravel pagination instance.
  *
  * @return LengthAwarePaginator
  */
 public function paginate()
 {
     return new LengthAwarePaginator($this->items, $this->getMeta('pagination.total'), $this->getMeta('pagination.per_page'), $this->getMeta('pagination.current_page'), ['path' => LengthAwarePaginator::resolveCurrentPath()]);
 }
示例#9
0
 /**
  * Paginate items.
  *
  * @param  array  $result
  * @param  string $modelClass
  *
  * @return \Illuminate\Pagination\LengthAwarePaginator
  */
 public function paginateHydrate($result, $modelClass = null)
 {
     // Get values
     $pagination = array_get($result, 'pagination', []);
     $items = array_get($result, 'items', []);
     $currentPage = array_get($pagination, 'next', 2) - 1;
     // Set pagination
     $perPage = array_get($pagination, 'perPage', array_get($pagination, 'per_page', 15));
     $total = array_get($pagination, 'total', null);
     // @deprecated
     if ($total === null) {
         $total = $perPage * array_get($pagination, 'last', 0);
     }
     // Set options
     $options = is_array($result) ? array_except($result, ['pagination', 'items', 'next', 'per_page', 'last']) : [];
     return new LengthAwarePaginator($this->hydrate($items, $modelClass), $total, $perPage, $currentPage, array_merge($options, ['path' => LengthAwarePaginator::resolveCurrentPath()]));
 }
 /**
  * Get All notifications
  *
  * @param           $to_id
  * @param           $limit
  * @param  int|null $paginate
  * @param  string   $orderDate
  * @param Closure   $filterScope
  * @return mixed
  */
 public function getAll($to_id, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null)
 {
     $notifications = $this->notifynderRepo->getAll($to_id, $this->entity, $limit, $paginate, $orderDate, $filterScope);
     if (is_int(intval($paginate)) && $paginate) {
         return new LengthAwarePaginator($notifications->parse(), $notifications->total(), $limit, $paginate, ['path' => LengthAwarePaginator::resolveCurrentPath()]);
     }
     return $notifications->parse();
 }
示例#11
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');
        }
    }
示例#12
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()]);
 }