Ejemplo n.º 1
0
 /**
  * Returns a paginated list of customers.
  *
  * @ApiDoc(
  *  resource=true,
  *  output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"="sonata_api_read"}
  * )
  *
  * @QueryParam(name="page", requirements="\d+", default="1", description="Page for customers list pagination (1-indexed)")
  * @QueryParam(name="count", requirements="\d+", default="10", description="Number of customers by page")
  * @QueryParam(name="orderBy", array=true, requirements="ASC|DESC", nullable=true, strict=true, description="Query customers order by clause (key is field, value is direction")
  *
  * @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
  *
  * @param ParamFetcherInterface $paramFetcher
  *
  * @return Sonata\DatagridBundle\Pager\PagerInterface
  */
 public function getCustomersAction(ParamFetcherInterface $paramFetcher)
 {
     $supportedCriteria = array('is_fake' => '');
     $page = $paramFetcher->get('page');
     $limit = $paramFetcher->get('count');
     $sort = $paramFetcher->get('orderBy');
     $criteria = array_intersect_key($paramFetcher->all(), $supportedCriteria);
     foreach ($criteria as $key => $value) {
         if (null === $value) {
             unset($criteria[$key]);
         }
     }
     if (!$sort) {
         $sort = array();
     } elseif (!is_array($sort)) {
         $sort = array($sort => 'asc');
     }
     return $this->customerManager->getPager($criteria, $page, $limit, $sort);
 }