/** * Retrieves the list of medias (paginated). * * @ApiDoc( * resource=true, * output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"="sonata_api_read"} * ) * * @QueryParam(name="page", requirements="\d+", default="1", description="Page for media list pagination") * @QueryParam(name="count", requirements="\d+", default="10", description="Number of medias by page") * @QueryParam(name="enabled", requirements="0|1", nullable=true, strict=true, description="Enabled/Disabled medias filter") * @QueryParam(name="orderBy", array=true, requirements="ASC|DESC", nullable=true, strict=true, description="Order by array (key is field, value is direction)") * * @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true) * * @param ParamFetcherInterface $paramFetcher * * @return PagerInterface */ public function getMediaAction(ParamFetcherInterface $paramFetcher) { $supportedCriteria = array('enabled' => ''); $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->mediaManager->getPager($criteria, $page, $limit, $sort); }