/**
  * Serialize the paginator.
  *
  * @param PaginatorInterface $paginator
  *
  * @return array
  */
 public function paginator(PaginatorInterface $paginator)
 {
     $currentPage = (int) $paginator->getCurrentPage();
     $pagination = ['count' => (int) $paginator->getCount(), 'per_page' => (int) $paginator->getPerPage(), 'current_page' => $currentPage, 'prev_page' => null, 'next_page' => null];
     if ($currentPage > 1) {
         $pagination['prev_page'] = $currentPage - 1;
     }
     if ($pagination['per_page'] == $pagination['count']) {
         $pagination['next_page'] = $currentPage + 1;
     }
     return ['pagination' => $pagination];
 }
Ejemplo n.º 2
0
 /**
  * Serialize the paginator.
  *
  * @param PaginatorInterface $paginator
  *
  * @return array
  */
 public function paginator(PaginatorInterface $paginator)
 {
     $currentPage = (int) $paginator->getCurrentPage();
     $lastPage = (int) $paginator->getLastPage();
     $pagination = ['total' => (int) $paginator->getTotal(), 'count' => (int) $paginator->getCount(), 'per_page' => (int) $paginator->getPerPage(), 'current_page' => $currentPage, 'total_pages' => $lastPage];
     $pagination['links'] = [];
     if ($currentPage > 1) {
         $pagination['links']['previous'] = $paginator->getUrl($currentPage - 1);
     }
     if ($currentPage < $lastPage) {
         $pagination['links']['next'] = $paginator->getUrl($currentPage + 1);
     }
     return ['pagination' => $pagination];
 }
Ejemplo n.º 3
0
 /**
  * Serialize the paginator.
  *
  * @param PaginatorInterface $paginator
  *
  * @return array
  */
 public function paginator(PaginatorInterface $paginator)
 {
     $currentPage = (int) $paginator->getCurrentPage();
     $lastPage = (int) $paginator->getLastPage();
     $pagination = ['total' => (int) $paginator->getTotal(), 'count' => (int) $paginator->getCount(), 'per_page' => (int) $paginator->getPerPage(), 'current_page' => $currentPage, 'total_pages' => $lastPage, 'has_more' => $currentPage < $lastPage];
     return ['pagination' => $pagination];
 }
Ejemplo n.º 4
0
 /**
  * Serialize the paginator.
  *
  * @param PaginatorInterface $paginator Paginator Interface
  *
  * @return array
  */
 public function paginator(PaginatorInterface $paginator)
 {
     $currentPage = (int) $paginator->getCurrentPage();
     $lastPage = (int) $paginator->getLastPage();
     $pagination = array('total' => (int) $paginator->getTotal(), 'count' => (int) $paginator->getCount(), 'per_page' => (int) $paginator->getPerPage(), 'current_page' => $currentPage, 'total_pages' => $lastPage);
     return array('pagination' => $pagination);
 }
Ejemplo n.º 5
0
 /**
  * override the default pagination field
  *
  * @param PaginatorInterface $paginator
  * @return array
  */
 public function paginator(PaginatorInterface $paginator)
 {
     //dd(get_class_methods($paginator) );
     $pag = $paginator->getPaginator();
     //dd(get_class_methods($pag));
     $currentPage = (int) $pag->currentPage();
     // --------------------------------------------------------------------
     $lastPage = (int) $pag->lastPage();
     $pagination = array('total' => (int) $pag->total(), 'count' => (int) $pag->count(), 'per_page' => (int) $pag->perPage(), 'current_page' => $currentPage, 'total_pages' => $lastPage);
     $pagination['links'] = array();
     if ($currentPage > 1) {
         $page = $currentPage - 1;
         $url = self::urlParamsResolver($pag->url($page), ['page' => $page]);
         $pagination['links']['prev'] = $url;
     }
     if ($currentPage < $lastPage) {
         $page = $currentPage + 1;
         $url = self::urlParamsResolver($pag->url($page), ['page' => $page]);
         $pagination['links']['next'] = $url;
     }
     return array('pagination' => $pagination);
 }
 /**
  * Create a new collection resource from a paginator with the given transformer.
  *
  * @param  \League\Fractal\Pagination\PaginatorInterface  $paginator
  * @param  object  $transformer
  * @param  string  $key
  * @return \Illuminate\Http\Response
  */
 public function withPaginator(FractalPaginatorInterface $paginator, $transformer, $key = null)
 {
     $resource = new FractalCollection($paginator->getCollection(), $transformer, $key);
     $resource->setPaginator($paginator);
     return $this->build($resource);
 }
 /**
  * Serialize the paginator.
  *
  * @param PaginatorInterface $paginator
  *
  * @return array
  */
 public function paginator(PaginatorInterface $paginator)
 {
     $currentPage = (int) $paginator->getCurrentPage();
     $lastPage = (int) $paginator->getLastPage();
     $pagination = ['total' => (int) $paginator->getTotal(), 'count' => (int) $paginator->getCount(), 'per_page' => (int) $paginator->getPerPage(), 'current_page' => $currentPage, 'total_pages' => $lastPage];
     $pagination['links'] = [];
     if ($currentPage !== 1) {
         $pagination['links']['first'] = $paginator->getUrl(1);
     }
     if ($currentPage > 1) {
         $pagination['links']['previous'] = $paginator->getUrl($currentPage - 1);
     }
     // add fast backward
     if (($fastBack = $currentPage - 10) >= 1) {
         $pagination['links']['fastback'] = $paginator->getUrl($fastBack);
     }
     if ($currentPage < $lastPage) {
         $pagination['links']['next'] = $paginator->getUrl($currentPage + 1);
     }
     // add fast backward
     if (($fastForward = $currentPage + 10) <= $lastPage) {
         $pagination['links']['fastforward'] = $paginator->getUrl($fastForward);
     }
     if ($lastPage > 1 && $currentPage !== $lastPage) {
         $pagination['links']['last'] = $paginator->getUrl($lastPage);
     }
     return ['pagination' => $pagination];
 }
 /**
  * Set Criteria On Paginator
  *
  * @param PaginatorInterface   $paginator Paginator
  * @param ElementCriteriaModel $criteria  Criteria
  */
 private function setCriteriaOnPaginator(PaginatorInterface $paginator, ElementCriteriaModel $criteria)
 {
     if (!$criteria->limit) {
         return $paginator;
     }
     return $paginator->setCriteria($criteria);
 }