From 400770123a639a6ae998b8eb1f9669f5ced60a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 14 Nov 2022 10:46:13 +0100 Subject: [PATCH] Features: [export] Apply person filters and aggreators on Count Evaluation --- .../Export/Export/CountEvaluation.php | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php b/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php index e62752d13..578cc1452 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php @@ -15,25 +15,22 @@ use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; use LogicException; use Symfony\Component\Form\FormBuilderInterface; -use function in_array; class CountEvaluation implements ExportInterface, GroupedExportInterface { - private EntityRepository $repository; + private EntityManagerInterface $entityManager; public function __construct( EntityManagerInterface $em ) { - $this->repository = $em->getRepository(AccompanyingPeriod::class); + $this->entityManager = $em; } public function buildForm(FormBuilderInterface $builder) @@ -96,22 +93,19 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface return $el['center']; }, $acl); - $qb = $this->repository->createQueryBuilder('acp'); - - if (!in_array('acpw', $qb->getAllAliases(), true)) { - $qb->join('acp.works', 'acpw'); - } - - if (!in_array('workeval', $qb->getAllAliases(), true)) { - $qb->join('acpw.accompanyingPeriodWorkEvaluations', 'workeval'); - } + $qb = $this->entityManager->createQueryBuilder(); $qb + ->from(AccompanyingPeriod\AccompanyingPeriodWorkEvaluation::class, 'workeval') + ->join('workeval.accompanyingPeriodWork', 'acpw') + ->join('acpw.accompanyingPeriod', 'acp') + ->join('acp.participations', 'acppart') + ->join('acppart.person', 'person') + ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere( $qb->expr()->exists( - 'SELECT 1 FROM ' . AccompanyingPeriodParticipation::class . ' acl_count_part - JOIN ' . PersonCenterHistory::class . ' acl_count_person_history WITH IDENTITY(acl_count_person_history.person) = IDENTITY(acl_count_part.person) - WHERE acl_count_part.accompanyingPeriod = acp.id AND acl_count_person_history.center IN (:authorized_centers) + 'SELECT 1 FROM ' . PersonCenterHistory::class . ' acl_count_person_history WHERE acl_count_person_history.person = person + AND acl_count_person_history.center IN (:authorized_centers) ' ) ) @@ -133,6 +127,7 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface Declarations::EVAL_TYPE, Declarations::SOCIAL_WORK_ACTION_TYPE, Declarations::ACP_TYPE, + Declarations::PERSON_TYPE, ]; } }