I have a controller that is used by different user, administrator can list all resources, but another role can't only list resources that are owned by himself, the list functionality logic for the two roles is same, the only difference is that I need to pass a extra parameter to query builder when the second role uses that function. I check the source code of the ResourceController, there is no way to pass a mandatory parameter to criteria for it would be override by criteria when it is configured in routing file. I think there should be a way that we can do this.
public function indexAction(Request $request)
{
$this->isGrantedOr403('index');
$criteria = $this->config->getCriteria();
$sorting = $this->config->getSorting();
$repository = $this->getRepository();
if ($this->config->isPaginated()) {
$resources = $this->resourceResolver->getResource(
$repository,
'createPaginator',
array($criteria, $sorting)
);
$resources->setCurrentPage($request->get('page', 1), true, true);
$resources->setMaxPerPage($this->config->getPaginationMaxPerPage());
if ($this->config->isApiRequest()) {
$resources = $this->getPagerfantaFactory()->createRepresentation(
$resources,
new Route(
$request->attributes->get('_route'),
array_merge($request->attributes->get('_route_params'), $request->query->all())
)
);
}
} else {
$resources = $this->resourceResolver->getResource(
$repository,
'findBy',
array($criteria, $sorting, $this->config->getLimit())
);
}
$view = $this
->view()
->setTemplate($this->config->getTemplate('index.html'))
->setTemplateVar($this->config->getPluralResourceName())
->setData($resources)
;
return $this->handleView($view);
}