コード例 #1
0
ファイル: LaravelCollection.php プロジェクト: larapackage/api
 /**
  * @inheritdoc
  */
 public function getNext()
 {
     $last = $this->paginator->getCollection()->last();
     if (is_null($last)) {
         return 0;
     }
     return (int) $last->id;
 }
コード例 #2
0
ファイル: Fractal.php プロジェクト: huglester/larasponse
 public function paginatedCollection(Paginator $paginator, $transformer = null, $resourceKey = null)
 {
     $paginator->appends(\Request::query());
     $resource = new Collection($paginator->getCollection(), $this->getTransformer($transformer), $resourceKey);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $this->manager->createData($resource)->toArray();
 }
コード例 #3
0
 function it_gets_the_next_position(Paginator $paginator, Collection $collection)
 {
     $next = 4;
     $model = new \stdClass();
     $model->id = $next;
     $paginator->getCollection()->shouldBeCalledTimes(1)->willReturn($collection);
     $collection->last()->shouldBeCalledTimes(1)->willReturn($model);
     $this->getNext()->shouldReturn($next);
 }
コード例 #4
0
 static function answerOkByPager(Paginator $paginator)
 {
     if ($paginator->getLastPage() == $paginator->getCurrentPage()) {
         $next_page = null;
     } else {
         $next_page = $paginator->getCurrentPage();
     }
     $next_page_url = $next_page ? \Request::url() . '?page=' . $next_page : null;
     return parent::json(['meta' => ['code' => 200], 'pagination' => ['next_url' => $next_page_url, 'next_page' => $next_page], 'data' => $paginator->getCollection()->toArray()], 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
 }
コード例 #5
0
 /**
  * @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;
 }
コード例 #6
0
ファイル: ApiController.php プロジェクト: ratiw/api
 protected function formatResponse(Paginator $paginator, BaseTransformer $transformer = null)
 {
     $data = $paginator->getCollection();
     if (!is_null($transformer)) {
         $data = $this->transformData($data, $transformer);
     }
     $this->appendsQueryString($paginator);
     return ["data" => $data, "meta" => ["pagination" => $this->getPagination($paginator)]];
 }
コード例 #7
-15
ファイル: Response.php プロジェクト: ryanmcoble/remedy
 /**
  * Respond with a paginator, and a transformer.
  *
  * @param Paginator $paginator
  * @param callable|\League\Fractal\TransformerAbstract $transformer
  * @param string $resourceKey
  * @param array $meta
  * @return \Illuminate\Http\Response
  */
 public function withPaginator(Paginator $paginator, $transformer, $resourceKey = null, $meta = [])
 {
     $resource = new Collection($paginator->getCollection(), $transformer, $resourceKey);
     $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
     foreach ($meta as $metaKey => $metaValue) {
         $resource->setMetaValue($metaKey, $metaValue);
     }
     $rootScope = $this->manager->createData($resource);
     return $this->withArray($rootScope->toArray());
 }