/**
  * @param PaginationInterface $pagination
  * @param Request             $request
  * @param Router              $router
  * @param array               $serializationGroups
  *
  * @return mixed
  */
 public function buildMultiObjectResponse(PaginationInterface $pagination, Request $request, Router $router, array $serializationGroups = array())
 {
     if (empty($pagination->getItems())) {
         return $this->handle(View::create(null, Response::HTTP_NO_CONTENT));
     }
     $paginationData = $pagination->getPaginationData();
     $link = $this->buildPaginationLink($paginationData, $request, $router);
     $headers = [];
     if (!empty($link)) {
         $headers['Link'] = $link;
     }
     if (isset($paginationData['totalCount'])) {
         $headers['X-Total-Count'] = $paginationData['totalCount'];
     }
     $view = View::create($pagination->getItems(), Response::HTTP_OK, $headers);
     $context = new SerializationContext();
     $context->setSerializeNull(true);
     if (!empty($serializationGroups)) {
         $context->setGroups($serializationGroups);
     }
     $view->setSerializationContext($context);
     return $this->handle($view);
 }
 /**
  * Public pagination method with knppaginator instance
  *
  * @\Mmoreram\ControllerExtraBundle\Annotation\Paginator(
  *      class = {
  *          "factory" = "Mmoreram\ControllerExtraBundle\Tests\FakeBundle\Factory\FakeFactory",
  *          "method" = "createNonStatic",
  *          "static" = false
  *      },
  *      page = "~page~",
  *      limit = "~limit~",
  *      orderBy = {
  *          { "x", "~field~", "~dir~", {
  *              "1" = "ASC",
  *              "2" = "DESC",
  *          }}
  *      }
  * )
  *
  * @\Mmoreram\ControllerExtraBundle\Annotation\JsonResponse()
  */
 public function paginatorKNPPaginatorAction(PaginationInterface $paginator)
 {
     return array('count' => $paginator->getTotalItemCount());
 }
Пример #3
0
 /**
  * Constructor.
  * @param PaginationInterface $pagination
  */
 public function __construct(PaginationInterface $pagination)
 {
     $this->metadata = ['page' => (int) $pagination->getCurrentPageNumber(), 'pages' => (int) $pagination->getPageCount(), 'limit' => (int) $pagination->getItemNumberPerPage(), 'total' => (int) $pagination->getTotalItemCount()];
     $this->items = $pagination->getItems();
 }