/**
  * @param Pagerfanta $pager  The pager
  * @param Route      $route  The collection's route
  * @param mixed      $inline Most of the time, a custom `CollectionRepresentation` instance
  *
  * @return PaginatedRepresentation
  */
 public function createRepresentation(Pagerfanta $pager, Route $route, $inline = null)
 {
     if (null === $inline) {
         $inline = new CollectionRepresentation($pager->getCurrentPageResults());
     }
     return new PaginatedRepresentation($inline, $route->getName(), $route->getParameters(), $pager->getCurrentPage(), $pager->getMaxPerPage(), $pager->getNbPages(), $this->getPageParameterName(), $this->getLimitParameterName(), $route->isAbsolute(), $pager->getNbResults());
 }
Пример #2
0
 /**
  * @param SlidingPagination $slidingPagination
  * @param Route $route
  * @param null $inline
  * @return PaginatedRepresentation
  */
 public function createRepresentation(SlidingPagination $slidingPagination, Route $route, $inline = null)
 {
     if (null === $inline) {
         $inline = new CollectionRepresentation($slidingPagination->getItems());
     }
     return new PaginatedRepresentation($inline, $route->getName(), $route->getParameters(), $slidingPagination->getCurrentPageNumber(), $slidingPagination->getItemNumberPerPage(), $slidingPagination->getPaginationData()['pageCount'], $this->getPageParameterName(), $this->getLimitParameterName(), $route->isAbsolute(), $slidingPagination->getTotalItemCount());
 }
Пример #3
0
 private function patchAbsolute(Relation $relation, $absolute)
 {
     $href = $relation->getHref();
     if ($href instanceof Route) {
         $href = new Route($href->getName(), $href->getParameters(), $absolute, $href->getGenerator());
     }
     return new Relation($relation->getName(), $href, $relation->getEmbed(), $relation->getAttributes(), $relation->getExclusion());
 }
 /**
  * @param AbstractPagination $pagination
  * @param Request            $request
  * @param string             $collectionName
  *
  * @return PaginatedRepresentation
  */
 public function createRepresentation(AbstractPagination $pagination, Request $request, $collectionName = '_items')
 {
     $route = new Route($request->get('_route', 'homepage'), $request->get('_route_params', $request->query->all()));
     $routeParameters = is_array($route->getParameters()) ? $route->getParameters() : [];
     $numberOfPages = 1;
     if ($pagination->getTotalItemCount() > 0 && $pagination->getItemNumberPerPage() > 0) {
         $numberOfPages = intval(ceil($pagination->getTotalItemCount() / $pagination->getItemNumberPerPage()));
     }
     $items = $pagination->getItems();
     switch (true) {
         case $items instanceof ArrayCollection:
             $items = $items->toArray();
             break;
         case $items instanceof \ArrayObject:
             $items = $items->getArrayCopy();
             break;
     }
     return new PaginatedRepresentation(new CollectionRepresentation(array_values($items), $collectionName), $route->getName(), $routeParameters, $pagination->getCurrentPageNumber(), $pagination->getItemNumberPerPage(), $numberOfPages, $this->getPageParameterName(), $this->getLimitParameterName(), $route->isAbsolute(), $pagination->getTotalItemCount());
 }
 /**
  * Construct a pagerfanta representation from the current request
  *
  * @param AdapterInterface $adapter - The adapter to use
  * @return QueryablePaginatedRepresentation
  */
 protected function getPagerfantaRepresentation(Request $request, AdapterInterface $adapter)
 {
     $pagerfanta = new Pagerfanta($adapter);
     $limit = $request->query->get('limit');
     $zeroLimit = false;
     if (!$limit && ($limit === 0 || $limit === '0')) {
         $limit = $pagerfanta->count();
         $zeroLimit = true;
     }
     if (!$limit) {
         $limit = 10;
     }
     $pagerfanta->setMaxPerPage($limit);
     $page = $request->query->get('page');
     $nbPages = $pagerfanta->getNbPages();
     if (!$page) {
         $page = 1;
     }
     // Avoid errors: redirect to max page
     if ($page > $nbPages) {
         $page = $nbPages;
     }
     $pagerfanta->setCurrentPage($page);
     $route = new Route($request->get('_route'), $request->attributes->get('_route_params'), false);
     return new QueryablePaginatedRepresentation(new CollectionRepresentation($pagerfanta->getCurrentPageResults()), $route->getName(), $route->getParameters(), $pagerfanta->getCurrentPage(), $zeroLimit ? 0 : $pagerfanta->getMaxPerPage(), $nbPages, $pagerfanta->count(), null, null, $route->isAbsolute(), $request->query->get('where'), $request->query->get('search'), $request->query->get('order'), null, null, null);
 }