diff --git a/CHANGELOG.md b/CHANGELOG.md index c3b010ccc..01837a378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,7 +100,7 @@ Version 1.5.12 Master branch ============= - - [CRUD] add step delete - [CRUD] improve index view in person CRUD +- [CRUD] filter by basis on person by default in EntityPersonCRUDController diff --git a/CRUD/Controller/EntityPersonCRUDController.php b/CRUD/Controller/EntityPersonCRUDController.php index aae821b3c..f729f8b02 100644 --- a/CRUD/Controller/EntityPersonCRUDController.php +++ b/CRUD/Controller/EntityPersonCRUDController.php @@ -19,8 +19,8 @@ namespace Chill\PersonBundle\CRUD\Controller; use Chill\MainBundle\CRUD\Controller\CRUDController; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Chill\PersonBundle\Entity\Person; +use Doctrine\ORM\QueryBuilder; /** * CRUD Controller for entities attached to a Person @@ -130,5 +130,33 @@ class EntityPersonCRUDController extends CRUDController } } + /** + * Override the base method to add a filtering step to a person. + * + * @param string $action + * @param Request $request + * @return QueryBuilder + */ + protected function buildQueryEntities(string $action, Request $request) + { + $qb = parent::buildQueryEntities($action, $request); + + return $this->filterQueryEntitiesByPerson($action, $qb, $request); + } + /** + * Add a where clause to the buildQuery + * + * @param string $action + * @param \Chill\PersonBundle\CRUD\Controller\QueryBuilder $qb + * @param Request $request + * @return \Chill\PersonBundle\CRUD\Controller\QueryBuilder + */ + protected function filterQueryEntitiesByPerson(string $action, QueryBuilder $qb, Request $request): QueryBuilder + { + $qb->andWhere($qb->expr()->eq('e.person', ':person')); + $qb->setParameter('person', $this->getPerson($request)); + + return $qb; + } }