protected function createPagedCollection(LengthAwarePaginator $paginator, TransformerAbstract $transformer)
 {
     $data = $paginator->getCollection();
     $collection = new Collection($data, $transformer);
     $collection->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $this->fractal->createData($collection)->toArray();
 }
Beispiel #2
0
 /**
  * @param Paginator $data
  * @param TransformerAbstract $transformer
  * @param array $headers
  * @return \Illuminate\Http\JsonResponse
  */
 public function respondWithPaginator(LengthAwarePaginator $data, TransformerAbstract $transformer, $headers = [])
 {
     $manager = new Manager();
     $manager->setSerializer(new ArraySerializer());
     $resource = new Collection($data->getCollection(), $transformer);
     $resource->setPaginator(new IlluminatePaginatorAdapter($data));
     $response = $manager->createData($resource)->toArray();
     return $this->respond(['post' => $this->_request->all(), 'data' => $response['data'], 'meta' => $response['meta'], 'error' => ['global' => '']], $headers);
 }
Beispiel #3
0
 /**
  * Get data .
  *
  * @param null $perPage
  * @return array
  */
 public function getData($perPage = null)
 {
     $source = $this->getSource();
     $items = $source['rows'];
     $offSet = @$_GET['page'] * $perPage - $perPage;
     $itemsForCurrentPage = array_slice($items, $offSet, $perPage, true);
     $paginator = new LengthAwarePaginator($itemsForCurrentPage, count($source['rows']), $perPage);
     return ['columns' => $this->source['columns'], 'rows' => $paginator->getCollection(), 'total' => $paginator->total()];
 }
Beispiel #4
0
 /**
  * Constructor.
  * @param Collection|LengthAwarePaginator $collection
  * @param string $class - optional
  */
 public function __construct($collection, $class = null)
 {
     if ($collection instanceof LengthAwarePaginator) {
         $this->paginator = $collection;
         $this->items = $collection->getCollection();
     } else {
         $this->items = $collection;
     }
     if ($class) {
         $this->setClass($class);
     }
 }
Beispiel #5
0
 public function transformPaginated(LengthAwarePaginator $paginator)
 {
     $collection = $paginator->getCollection();
     try {
         $transformer = TransformerFactory::makeForCollection($collection);
         $resource = new Collection($collection, $transformer);
         $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
         return $this->manager->createData($resource)->toArray();
     } catch (\OutOfRangeException $e) {
         $emptyResource = new Collection([], []);
         $emptyResource->setPaginator(new IlluminatePaginatorAdapter($paginator));
         return $this->manager->createData($emptyResource)->toArray();
     }
 }
 /**
  * @param AbstractPaginator|LengthAwarePaginator|Paginator $paginator
  * @return \League\Fractal\Resource\Collection
  */
 protected function transformPaginator($paginator)
 {
     $collection = $paginator->getCollection();
     $resource = new Collection($collection, $this->getTransformer(), $this->resourceKeyCollection);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $resource;
 }
 /**
  * @param LengthAwarePaginator $paged
  *
  * @return PaginatedRepresentation
  */
 public function formateHatoeasPaged(LengthAwarePaginator $paged)
 {
     $request = \App::make('request');
     $params = array_merge($request->route()[2], $request->all());
     return new PaginatedRepresentation(new CollectionRepresentation($paged->getCollection(), null, $request->path()), $request->route()[1]['as'], $params, $paged->currentPage(), $paged->perPage(), $paged->lastPage(), 'page', 'per_page', true, $paged->total());
 }
Beispiel #8
0
 public static function wrapPager(LengthAwarePaginator $pager)
 {
     $collection = static::wrapCollection($pager->getCollection());
     return new LengthAwarePaginator($collection, $pager->total(), $pager->perPage(), $pager->currentPage());
 }
Beispiel #9
0
 /**
  * @param LengthAwarePaginator $pagination
  * @param null|Fractal\TransformerAbstract $transformer
  * @return array
  */
 private function handlePagination(LengthAwarePaginator $pagination, $transformer = null)
 {
     $transformer = $transformer ?: TransformerFactory::create(class_basename($pagination->getCollection()->first()));
     $resource = new Fractal\Resource\Collection($pagination->getCollection(), $transformer);
     $resource->setPaginator(new Fractal\Pagination\IlluminatePaginatorAdapter($pagination));
     return $this->handleResource($resource);
 }