diff --git a/.changes/unreleased/Feature-20231019-171900.yaml b/.changes/unreleased/Feature-20231019-171900.yaml new file mode 100644 index 000000000..d8ee98cdd --- /dev/null +++ b/.changes/unreleased/Feature-20231019-171900.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: '[export] create a parameter that will force to skip the filtering by center + (ACL) when generating an export' +time: 2023-10-19T17:19:00.51809407+02:00 +custom: + Issue: "179" diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php index 9cdbc183d..d8b204e8c 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php @@ -11,8 +11,8 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Export\Export\LinkedToACP; -use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Export\Declarations; +use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; @@ -21,19 +21,19 @@ use Chill\MainBundle\Export\GroupedExportInterface; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Export\Declarations as PersonDeclarations; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class AvgActivityDuration implements ExportInterface, GroupedExportInterface { - protected EntityRepository $repository; + private readonly bool $filterStatsByCenters; public function __construct( - EntityManagerInterface $em, + private readonly ActivityRepository $activityRepository, + ParameterBagInterface $parameterBag, ) { - $this->repository = $em->getRepository(Activity::class); + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; } public function buildForm(FormBuilderInterface $builder) {} @@ -91,23 +91,25 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface { $centers = array_map(static fn ($el) => $el['center'], $acl); - $qb = $this->repository->createQueryBuilder('activity'); + $qb = $this->activityRepository->createQueryBuilder('activity'); $qb ->join('activity.accompanyingPeriod', 'acp') ->select('AVG(activity.durationTime) as export_avg_activity_duration') ->andWhere($qb->expr()->isNotNull('activity.durationTime')); - $qb - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part + if ($this->filterStatsByCenters) { + $qb + ->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) ' + ) ) - ) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php index 58ac6e829..acfb073f5 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php @@ -24,16 +24,21 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterface { protected EntityRepository $repository; + private readonly bool $filterStatsByCenters; + public function __construct( EntityManagerInterface $em, + ParameterBagInterface $parameterBag, ) { $this->repository = $em->getRepository(Activity::class); + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; } public function buildForm(FormBuilderInterface $builder) @@ -101,16 +106,18 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac ->select('AVG(activity.travelTime) as export_avg_activity_visit_duration') ->andWhere($qb->expr()->isNotNull('activity.travelTime')); - $qb - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part + if ($this->filterStatsByCenters) { + $qb + ->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) ' + ) ) - ) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/CountActivity.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/CountActivity.php index 39c79cf1f..dfd5d966f 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/CountActivity.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/CountActivity.php @@ -24,16 +24,21 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class CountActivity implements ExportInterface, GroupedExportInterface { protected EntityRepository $repository; + private readonly bool $filterStatsByCenters; + public function __construct( EntityManagerInterface $em, + ParameterBagInterface $parameterBag, ) { $this->repository = $em->getRepository(Activity::class); + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; } public function buildForm(FormBuilderInterface $builder) {} @@ -95,16 +100,18 @@ class CountActivity implements ExportInterface, GroupedExportInterface ->createQueryBuilder('activity') ->join('activity.accompanyingPeriod', 'acp'); - $qb - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part + if ($this->filterStatsByCenters) { + $qb + ->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) ' + ) ) - ) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/ListActivity.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/ListActivity.php index 45233d97f..270fbd12c 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/ListActivity.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/ListActivity.php @@ -22,11 +22,21 @@ use Chill\MainBundle\Export\Helper\TranslatableStringExportLabelHelper; use Chill\MainBundle\Export\ListInterface; use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class ListActivity implements ListInterface, GroupedExportInterface { - public function __construct(private readonly ListActivityHelper $helper, private readonly EntityManagerInterface $entityManager, private readonly TranslatableStringExportLabelHelper $translatableStringExportLabelHelper) {} + private readonly bool $filterStatsByCenters; + + public function __construct( + private readonly ListActivityHelper $helper, + private readonly EntityManagerInterface $entityManager, + private readonly TranslatableStringExportLabelHelper $translatableStringExportLabelHelper, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -107,21 +117,27 @@ class ListActivity implements ListInterface, GroupedExportInterface ->join('activity.accompanyingPeriod', 'acp') ->leftJoin('acp.participations', 'acppart') ->leftJoin('acppart.person', 'person') - ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 + ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL'); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + '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) ' + ) ) - ) + ->setParameter('authorized_centers', $centers); + } + + $qb // some grouping are necessary ->addGroupBy('acp.id') ->addOrderBy('activity.date') - ->addOrderBy('activity.id') - ->setParameter('authorized_centers', $centers); + ->addOrderBy('activity.id'); $this->helper->addSelect($qb); diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php index a8d6f10fd..159fcf78d 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php @@ -24,16 +24,20 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class SumActivityDuration implements ExportInterface, GroupedExportInterface { protected EntityRepository $repository; + private readonly bool $filterStatsByCenters; public function __construct( EntityManagerInterface $em, + ParameterBagInterface $parameterBag, ) { $this->repository = $em->getRepository(Activity::class); + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; } public function buildForm(FormBuilderInterface $builder) @@ -101,16 +105,18 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface $qb->select('SUM(activity.durationTime) as export_sum_activity_duration') ->andWhere($qb->expr()->isNotNull('activity.durationTime')); - $qb - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part + if ($this->filterStatsByCenters) { + $qb + ->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) ' + ) ) - ) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php index dae572ba5..27502e2b0 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php @@ -24,16 +24,20 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class SumActivityVisitDuration implements ExportInterface, GroupedExportInterface { protected EntityRepository $repository; + private readonly bool $filterStatsByCenters; public function __construct( EntityManagerInterface $em, + ParameterBagInterface $parameterBag, ) { $this->repository = $em->getRepository(Activity::class); + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; } public function buildForm(FormBuilderInterface $builder) @@ -101,16 +105,18 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac $qb->select('SUM(activity.travelTime) as export_sum_activity_visit_duration') ->andWhere($qb->expr()->isNotNull('activity.travelTime')); - $qb - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part + if ($this->filterStatsByCenters) { + $qb + ->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) ' + ) ) - ) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/CountActivity.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/CountActivity.php index dbc7e3fde..e0a95b1f5 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/CountActivity.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/CountActivity.php @@ -19,11 +19,19 @@ use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class CountActivity implements ExportInterface, GroupedExportInterface { - public function __construct(protected ActivityRepository $activityRepository) {} + private readonly bool $filterStatsByCenters; + + public function __construct( + private readonly ActivityRepository $activityRepository, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) {} @@ -82,23 +90,25 @@ class CountActivity implements ExportInterface, GroupedExportInterface $qb = $this->activityRepository ->createQueryBuilder('activity') - ->join('activity.person', 'person') - ->join('person.centerHistory', 'centerHistory'); + ->join('activity.person', 'person'); $qb->select('COUNT(activity.id) as export_count_activity'); - $qb - ->where( - $qb->expr()->andX( - $qb->expr()->lte('centerHistory.startDate', 'activity.date'), - $qb->expr()->orX( - $qb->expr()->isNull('centerHistory.endDate'), - $qb->expr()->gt('centerHistory.endDate', 'activity.date') + if ($this->filterStatsByCenters) { + $qb + ->join('person.centerHistory', 'centerHistory') + ->where( + $qb->expr()->andX( + $qb->expr()->lte('centerHistory.startDate', 'activity.date'), + $qb->expr()->orX( + $qb->expr()->isNull('centerHistory.endDate'), + $qb->expr()->gt('centerHistory.endDate', 'activity.date') + ) ) ) - ) - ->andWhere($qb->expr()->in('centerHistory.center', ':centers')) - ->setParameter('centers', $centers); + ->andWhere($qb->expr()->in('centerHistory.center', ':centers')) + ->setParameter('centers', $centers); + } return $qb; } diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/ListActivity.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/ListActivity.php index 50b8ace2a..f7b5f3a8a 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/ListActivity.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/ListActivity.php @@ -23,6 +23,7 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints\Callback; @@ -44,8 +45,17 @@ class ListActivity implements ListInterface, GroupedExportInterface 'person_lastname', 'person_id', ]; + private readonly bool $filterStatsByCenters; - public function __construct(protected EntityManagerInterface $entityManager, protected TranslatorInterface $translator, protected TranslatableStringHelperInterface $translatableStringHelper, private readonly ActivityRepository $activityRepository) {} + public function __construct( + protected EntityManagerInterface $entityManager, + protected TranslatorInterface $translator, + protected TranslatableStringHelperInterface $translatableStringHelper, + private readonly ActivityRepository $activityRepository, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -188,20 +198,22 @@ class ListActivity implements ListInterface, GroupedExportInterface $qb ->from('ChillActivityBundle:Activity', 'activity') - ->join('activity.person', 'actperson') - ->join('actperson.centerHistory', 'centerHistory'); + ->join('activity.person', 'actperson'); - $qb->where( - $qb->expr()->andX( - $qb->expr()->lte('centerHistory.startDate', 'activity.date'), - $qb->expr()->orX( - $qb->expr()->isNull('centerHistory.endDate'), - $qb->expr()->gt('centerHistory.endDate', 'activity.date') + if ($this->filterStatsByCenters) { + $qb->join('actperson.centerHistory', 'centerHistory'); + $qb->where( + $qb->expr()->andX( + $qb->expr()->lte('centerHistory.startDate', 'activity.date'), + $qb->expr()->orX( + $qb->expr()->isNull('centerHistory.endDate'), + $qb->expr()->gt('centerHistory.endDate', 'activity.date') + ) ) ) - ) - ->andWhere($qb->expr()->in('centerHistory.center', ':centers')) - ->setParameter('centers', $centers); + ->andWhere($qb->expr()->in('centerHistory.center', ':centers')) + ->setParameter('centers', $centers); + } foreach ($this->fields as $f) { if (\in_array($f, $data['fields'], true)) { diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/StatActivityDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/StatActivityDuration.php index 6f254bb08..3cdadac67 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/StatActivityDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToPerson/StatActivityDuration.php @@ -20,6 +20,7 @@ use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; /** @@ -30,17 +31,21 @@ use Symfony\Component\Form\FormBuilderInterface; class StatActivityDuration implements ExportInterface, GroupedExportInterface { final public const SUM = 'sum'; + private readonly bool $filterStatsByCenters; /** * @param string $action the stat to perform */ public function __construct( private readonly ActivityRepository $activityRepository, + ParameterBagInterface $parameterBag, /** * The action for this report. */ protected string $action = 'sum' - ) {} + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) {} @@ -119,21 +124,23 @@ class StatActivityDuration implements ExportInterface, GroupedExportInterface } $qb->select($select) - ->join('activity.person', 'person') - ->join('person.centerHistory', 'centerHistory'); + ->join('activity.person', 'person'); - $qb - ->where( - $qb->expr()->andX( - $qb->expr()->lte('centerHistory.startDate', 'activity.date'), - $qb->expr()->orX( - $qb->expr()->isNull('centerHistory.endDate'), - $qb->expr()->gt('centerHistory.endDate', 'activity.date') + if ($this->filterStatsByCenters) { + $qb + ->join('person.centerHistory', 'centerHistory') + ->where( + $qb->expr()->andX( + $qb->expr()->lte('centerHistory.startDate', 'activity.date'), + $qb->expr()->orX( + $qb->expr()->isNull('centerHistory.endDate'), + $qb->expr()->gt('centerHistory.endDate', 'activity.date') + ) ) ) - ) - ->andWhere($qb->expr()->in('centerHistory.center', ':centers')) - ->setParameter('centers', $centers); + ->andWhere($qb->expr()->in('centerHistory.center', ':centers')) + ->setParameter('centers', $centers); + } return $qb; } diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/AvgActivityDurationTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/AvgActivityDurationTest.php index 5f9b635ee..c8010c327 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/AvgActivityDurationTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/AvgActivityDurationTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP; use Chill\ActivityBundle\Export\Export\LinkedToACP\AvgActivityDuration; +use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\MainBundle\Test\Export\AbstractExportTest; /** @@ -21,18 +22,17 @@ use Chill\MainBundle\Test\Export\AbstractExportTest; */ final class AvgActivityDurationTest extends AbstractExportTest { - private AvgActivityDuration $export; - protected function setUp(): void { self::bootKernel(); - - $this->export = self::$container->get('chill.activity.export.avg_activity_duration_linked_to_acp'); } public function getExport() { - return $this->export; + $activityRepository = self::$container->get(ActivityRepository::class); + + yield new AvgActivityDuration($activityRepository, $this->getParameters(true)); + yield new AvgActivityDuration($activityRepository, $this->getParameters(false)); } public function getFormData(): array diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/AvgActivityVisitDurationTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/AvgActivityVisitDurationTest.php index b15462912..414e72960 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/AvgActivityVisitDurationTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/AvgActivityVisitDurationTest.php @@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP; use Chill\ActivityBundle\Export\Export\LinkedToACP\AvgActivityVisitDuration; use Chill\MainBundle\Test\Export\AbstractExportTest; +use Doctrine\ORM\EntityManagerInterface; /** * @internal @@ -21,18 +22,17 @@ use Chill\MainBundle\Test\Export\AbstractExportTest; */ final class AvgActivityVisitDurationTest extends AbstractExportTest { - private AvgActivityVisitDuration $export; - protected function setUp(): void { self::bootKernel(); - - $this->export = self::$container->get('chill.activity.export.avg_activity_visit_duration_linked_to_acp'); } public function getExport() { - return $this->export; + $em = self::$container->get(EntityManagerInterface::class); + + yield new AvgActivityVisitDuration($em, $this->getParameters(true)); + yield new AvgActivityVisitDuration($em, $this->getParameters(false)); } public function getFormData(): array diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/CountActivityTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/CountActivityTest.php index 46279ebd8..174bcc790 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/CountActivityTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/CountActivityTest.php @@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP; use Chill\ActivityBundle\Export\Export\LinkedToACP\CountActivity; use Chill\MainBundle\Test\Export\AbstractExportTest; +use Doctrine\ORM\EntityManagerInterface; /** * @internal @@ -21,18 +22,17 @@ use Chill\MainBundle\Test\Export\AbstractExportTest; */ final class CountActivityTest extends AbstractExportTest { - private CountActivity $export; - protected function setUp(): void { self::bootKernel(); - - $this->export = self::$container->get('chill.activity.export.count_activity_linked_to_acp'); } public function getExport() { - return $this->export; + $em = self::$container->get(EntityManagerInterface::class); + + yield new CountActivity($em, $this->getParameters(true)); + yield new CountActivity($em, $this->getParameters(false)); } public function getFormData(): array diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/SumActivityDurationTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/SumActivityDurationTest.php index c4f91f52e..f538ad3ea 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/SumActivityDurationTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/SumActivityDurationTest.php @@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP; use Chill\ActivityBundle\Export\Export\LinkedToACP\SumActivityDuration; use Chill\MainBundle\Test\Export\AbstractExportTest; +use Doctrine\ORM\EntityManagerInterface; /** * @internal @@ -21,18 +22,17 @@ use Chill\MainBundle\Test\Export\AbstractExportTest; */ final class SumActivityDurationTest extends AbstractExportTest { - private SumActivityDuration $export; - protected function setUp(): void { self::bootKernel(); - - $this->export = self::$container->get('chill.activity.export.sum_activity_duration_linked_to_acp'); } public function getExport() { - return $this->export; + $em = self::$container->get(EntityManagerInterface::class); + + yield new SumActivityDuration($em, $this->getParameters(true)); + yield new SumActivityDuration($em, $this->getParameters(false)); } public function getFormData(): array diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/SumActivityVisitDurationTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/SumActivityVisitDurationTest.php index 6bd7e9d19..95d4b597f 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/SumActivityVisitDurationTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToACP/SumActivityVisitDurationTest.php @@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP; use Chill\ActivityBundle\Export\Export\LinkedToACP\SumActivityVisitDuration; use Chill\MainBundle\Test\Export\AbstractExportTest; +use Doctrine\ORM\EntityManagerInterface; /** * @internal @@ -32,7 +33,10 @@ final class SumActivityVisitDurationTest extends AbstractExportTest public function getExport() { - return $this->export; + $em = self::$container->get(EntityManagerInterface::class); + + yield new SumActivityVisitDuration($em, $this->getParameters(true)); + yield new SumActivityVisitDuration($em, $this->getParameters(false)); } public function getFormData(): array diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/CountActivityTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/CountActivityTest.php index 61ae15604..8759dceb3 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/CountActivityTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/CountActivityTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToPerson; use Chill\ActivityBundle\Export\Export\LinkedToPerson\CountActivity; +use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\MainBundle\Test\Export\AbstractExportTest; /** @@ -21,18 +22,17 @@ use Chill\MainBundle\Test\Export\AbstractExportTest; */ final class CountActivityTest extends AbstractExportTest { - private CountActivity $export; - protected function setUp(): void { self::bootKernel(); - - $this->export = self::$container->get('chill.activity.export.count_activity_linked_to_person'); } public function getExport() { - return $this->export; + $activityRepository = self::$container->get(ActivityRepository::class); + + yield new CountActivity($activityRepository, $this->getParameters(true)); + yield new CountActivity($activityRepository, $this->getParameters(false)); } public function getFormData(): array diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/ListActivityTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/ListActivityTest.php index f474b1fe6..a6b6903f2 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/ListActivityTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/ListActivityTest.php @@ -12,8 +12,12 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToPerson; use Chill\ActivityBundle\Export\Export\LinkedToPerson\ListActivity; +use Chill\ActivityBundle\Repository\ActivityRepository; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Test\Export\AbstractExportTest; +use Doctrine\ORM\EntityManagerInterface; use Prophecy\PhpUnit\ProphecyTrait; +use Symfony\Contracts\Translation\TranslatorInterface; /** * @internal @@ -24,14 +28,12 @@ final class ListActivityTest extends AbstractExportTest { use ProphecyTrait; - private ListActivity $export; + private readonly ListActivity $export; protected function setUp(): void { self::bootKernel(); - $this->export = self::$container->get('chill.activity.export.list_activity_linked_to_person'); - $request = $this->prophesize() ->willExtend(\Symfony\Component\HttpFoundation\Request::class); @@ -43,7 +45,26 @@ final class ListActivityTest extends AbstractExportTest public function getExport() { - return $this->export; + $em = self::$container->get(EntityManagerInterface::class); + $translator = self::$container->get(TranslatorInterface::class); + $translatableStringHelper = self::$container->get(TranslatableStringHelperInterface::class); + $activityRepository = self::$container->get(ActivityRepository::class); + + yield new ListActivity( + $em, + $translator, + $translatableStringHelper, + $activityRepository, + $this->getParameters(true) + ); + + yield new ListActivity( + $em, + $translator, + $translatableStringHelper, + $activityRepository, + $this->getParameters(false) + ); } public function getFormData() diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/StatActivityDurationTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/StatActivityDurationTest.php index 11fb84a9a..8f4e98452 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/StatActivityDurationTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Export/LinkedToPerson/StatActivityDurationTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToPerson; use Chill\ActivityBundle\Export\Export\LinkedToPerson\StatActivityDuration; +use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\MainBundle\Test\Export\AbstractExportTest; /** @@ -23,18 +24,18 @@ use Chill\MainBundle\Test\Export\AbstractExportTest; */ final class StatActivityDurationTest extends AbstractExportTest { - private StatActivityDuration $export; + private readonly StatActivityDuration $export; protected function setUp(): void { self::bootKernel(); - - $this->export = self::$container->get('chill.activity.export.sum_activity_duration_linked_to_person'); } public function getExport() { - return $this->export; + $activityRepository = self::$container->get(ActivityRepository::class); + yield new StatActivityDuration($activityRepository, $this->getParameters(true), 'sum'); + yield new StatActivityDuration($activityRepository, $this->getParameters(false), 'sum'); } public function getFormData(): array diff --git a/src/Bundle/ChillCalendarBundle/Export/Export/CountCalendars.php b/src/Bundle/ChillCalendarBundle/Export/Export/CountCalendars.php index 2e156d7a0..f643eaa68 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Export/CountCalendars.php +++ b/src/Bundle/ChillCalendarBundle/Export/Export/CountCalendars.php @@ -25,7 +25,9 @@ use Symfony\Component\Validator\Exception\LogicException; class CountCalendars implements ExportInterface, GroupedExportInterface { - public function __construct(private readonly CalendarRepository $calendarRepository) {} + public function __construct( + private readonly CalendarRepository $calendarRepository, + ) {} public function buildForm(FormBuilderInterface $builder) { diff --git a/src/Bundle/ChillMainBundle/Controller/ExportController.php b/src/Bundle/ChillMainBundle/Controller/ExportController.php index abae07f9c..3aaac9a68 100644 --- a/src/Bundle/ChillMainBundle/Controller/ExportController.php +++ b/src/Bundle/ChillMainBundle/Controller/ExportController.php @@ -27,6 +27,7 @@ use Chill\MainBundle\Security\Authorization\SavedExportVoter; use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\FormFactoryInterface; @@ -46,6 +47,8 @@ use Symfony\Contracts\Translation\TranslatorInterface; */ class ExportController extends AbstractController { + private readonly bool $filterStatsByCenters; + public function __construct( private readonly ChillRedis $redis, private readonly ExportManager $exportManager, @@ -56,8 +59,11 @@ class ExportController extends AbstractController private readonly EntityManagerInterface $entityManager, private readonly ExportFormHelper $exportFormHelper, private readonly SavedExportRepositoryInterface $savedExportRepository, - private readonly Security $security - ) {} + private readonly Security $security, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } /** * @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/exports/download/{alias}", name="chill_main_export_download", methods={"GET"}) @@ -484,9 +490,13 @@ class ExportController extends AbstractController $alias = $rawData['alias']; - $formCenters = $this->createCreateFormExport($alias, 'generate_centers', [], $savedExport); - $formCenters->submit($rawData['centers']); - $dataCenters = $formCenters->getData(); + if ($this->filterStatsByCenters) { + $formCenters = $this->createCreateFormExport($alias, 'generate_centers', [], $savedExport); + $formCenters->submit($rawData['centers']); + $dataCenters = $formCenters->getData(); + } else { + $dataCenters = ['centers' => []]; + } $formExport = $this->createCreateFormExport($alias, 'generate_export', $dataCenters, $savedExport); $formExport->submit($rawData['export']); @@ -513,6 +523,14 @@ class ExportController extends AbstractController */ private function selectCentersStep(Request $request, DirectExportInterface|ExportInterface $export, $alias, SavedExport $savedExport = null) { + if (!$this->filterStatsByCenters) { + return $this->redirectToRoute('chill_main_export_new', [ + 'step' => $this->getNextStep('centers', $export), + 'alias' => $alias, + 'from_saved' => $request->get('from_saved', ''), + ]); + } + /** @var \Chill\MainBundle\Export\ExportManager $exportManager */ $exportManager = $this->exportManager; diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index 76e160b52..8bd3e35f4 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -116,8 +116,12 @@ class Configuration implements ConfigurationInterface ->booleanNode('form_show_centers') ->defaultTrue() ->end() + ->booleanNode('filter_stats_by_center') + ->defaultTrue() + ->info("if set to false, the exports won't take into account the center of the people") ->end() ->end() + ->end() // end of 'acl' ->booleanNode('access_global_history') ->defaultTrue() ->end() diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php index 8d845b413..bb4cdc6f7 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php @@ -11,11 +11,15 @@ declare(strict_types=1); namespace Chill\MainBundle\Test\Export; +use Chill\MainBundle\Export\DirectExportInterface; +use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Test\PrepareClientTrait; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\NativeQuery; use Doctrine\ORM\QueryBuilder; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; /** * This class provide a set of tests for exports. @@ -94,7 +98,7 @@ abstract class AbstractExportTest extends WebTestCase /** * Create an instance of the report to test. * - * @return \Chill\MainBundle\Export\ExportInterface an instance of the export to test + * @return ExportInterface|DirectExportInterface|iterable|iterable an instance of the export to test */ abstract public function getExport(); @@ -116,19 +120,40 @@ abstract class AbstractExportTest extends WebTestCase */ abstract public function getModifiersCombination(); + protected function getParameters(bool $filterStatsByCenter): ParameterBagInterface + { + return new ParameterBag(['chill_main' => ['acl' => ['filter_stats_by_center' => $filterStatsByCenter]]]); + } + + /** + * wrap the results of @see{self::getExports()}, which may be an iterable or an export into an iterble. + */ + private function getExports(): iterable + { + $exports = $this->getExport(); + + if (is_iterable($exports)) { + return $exports; + } + + return [$exports]; + } + /** * Test the formatters type are string. */ public function testGetAllowedFormattersType() { - $formattersTypes = $this->getExport()->getAllowedFormattersTypes(); + foreach ($this->getExports() as $export) { + $formattersTypes = $export->getAllowedFormattersTypes(); - $this->assertContainsOnly( - 'string', - $formattersTypes, - true, - 'Test that the method `getAllowedFormattersTypes` returns an array of string' - ); + $this->assertContainsOnly( + 'string', + $formattersTypes, + true, + 'Test that the method `getAllowedFormattersTypes` returns an array of string' + ); + } } /** @@ -136,17 +161,17 @@ abstract class AbstractExportTest extends WebTestCase */ public function testGetDescription() { - $export = $this->getExport(); - - $this->assertIsString( - $export->getDescription(), - 'Assert that the `getDescription` method return a string' - ); - $this->assertNotEmpty( - $export->getDescription(), - 'Assert that the `getDescription` method does not return an empty ' - .'string.' - ); + foreach ($this->getExports() as $export) { + $this->assertIsString( + $export->getDescription(), + 'Assert that the `getDescription` method return a string' + ); + $this->assertNotEmpty( + $export->getDescription(), + 'Assert that the `getDescription` method does not return an empty ' + .'string.' + ); + } } /** @@ -156,19 +181,21 @@ abstract class AbstractExportTest extends WebTestCase */ public function testGetQueryKeys(array $data) { - $queryKeys = $this->getExport()->getQueryKeys($data); + foreach ($this->getExports() as $export) { + $queryKeys = $export->getQueryKeys($data); - $this->assertContainsOnly( - 'string', - $queryKeys, - true, - 'test that the query keys returned by `getQueryKeys` are only strings' - ); - $this->assertGreaterThanOrEqual( - 1, - \count($queryKeys), - 'test that there are at least one query key returned' - ); + $this->assertContainsOnly( + 'string', + $queryKeys, + true, + 'test that the query keys returned by `getQueryKeys` are only strings' + ); + $this->assertGreaterThanOrEqual( + 1, + \count($queryKeys), + 'test that there are at least one query key returned' + ); + } } /** @@ -187,61 +214,70 @@ abstract class AbstractExportTest extends WebTestCase */ public function testGetResultsAndLabels($modifiers, $acl, array $data) { - // it is more convenient to group the `getResult` and `getLabels` test - // due to the fact that testing both methods use the same tools. + foreach ($this->getExports() as $export) { + // it is more convenient to group the `getResult` and `getLabels` test + // due to the fact that testing both methods use the same tools. - $queryKeys = $this->getExport()->getQueryKeys($data); - $query = $this->getExport()->initiateQuery($modifiers, $acl, $data); + $queryKeys = $export->getQueryKeys($data); + $query = $export->initiateQuery($modifiers, $acl, $data); - // limit the result for the query for performance reason (only for QueryBuilder, - // not possible in NativeQuery) - if ($query instanceof QueryBuilder) { - $query->setMaxResults(1); - } + // limit the result for the query for performance reason (only for QueryBuilder, + // not possible in NativeQuery) + if ($query instanceof QueryBuilder) { + $query->setMaxResults(1); + } - $results = $this->getExport()->getResult($query, $data); + $results = $export->getResult($query, $data); - $this->assertIsArray( - $results, - 'assert that the returned result is an array' - ); - - if (0 === \count($results)) { - $this->markTestIncomplete('The result is empty. We cannot process tests ' - .'on results'); - } - - // testing the result - $result = $results[0]; - - $this->assertTrue( - is_iterable($result), - 'test that each row in the result is traversable or an array' - ); - - foreach ($result as $key => $value) { - $this->assertContains( - $key, - $queryKeys, - 'test that each key is present in `getQueryKeys`' + $this->assertIsArray( + $results, + 'assert that the returned result is an array' ); - $closure = $this->getExport()->getLabels($key, [$value], $data); + if (0 === \count($results)) { + $this->markTestIncomplete('The result is empty. We cannot process tests ' + .'on results'); + } + + // testing the result + $result = $results[0]; $this->assertTrue( - \is_callable($closure, false), - 'test that the `getLabels` for key is a callable' + is_iterable($result), + 'test that each row in the result is traversable or an array' ); - $this->assertTrue( - // conditions - \is_string((string) \call_user_func($closure, '_header')) - && !empty(\call_user_func($closure, '_header')) - && '_header' !== \call_user_func($closure, '_header'), - // message - sprintf('Test that the callable return by `getLabels` for key %s ' - .'can provide an header', $key) - ); + $i = 0; + foreach ($result as $key => $value) { + $this->assertContains( + $key, + $queryKeys, + 'test that each key is present in `getQueryKeys`' + ); + + $closure = $export->getLabels($key, [$value], $data); + + $this->assertTrue( + \is_callable($closure, false), + 'test that the `getLabels` for key is a callable' + ); + + $this->assertTrue( + // conditions + \is_string((string) \call_user_func($closure, '_header')) + && !empty(\call_user_func($closure, '_header')) + && '_header' !== \call_user_func($closure, '_header'), + // message + sprintf('Test that the callable return by `getLabels` for key %s ' + .'can provide an header', $key) + ); + ++$i; + + if ($i > 15) { + // do not iterate on each result + break; + } + } } } @@ -250,14 +286,14 @@ abstract class AbstractExportTest extends WebTestCase */ public function testGetType() { - $export = $this->getExport(); - - $this->assertIsString( - $export->getType(), - 'Assert that the `getType` method return a string' - ); - $this->assertNotEmpty($export->getType(), 'Assert that the `getType` method' - .' does not return an empty string.'); + foreach ($this->getExports() as $export) { + $this->assertIsString( + $export->getType(), + 'Assert that the `getType` method return a string' + ); + $this->assertNotEmpty($export->getType(), 'Assert that the `getType` method' + .' does not return an empty string.'); + } } /** @@ -272,34 +308,36 @@ abstract class AbstractExportTest extends WebTestCase */ public function testInitiateQuery(mixed $modifiers, mixed $acl, mixed $data) { - $query = $this->getExport()->initiateQuery($modifiers, $acl, $data); + foreach ($this->getExports() as $export) { + $query = $export->initiateQuery($modifiers, $acl, $data); - $this->assertTrue( - $query instanceof QueryBuilder || $query instanceof NativeQuery, - sprintf( - 'Assert that the returned query is an instance of %s or %s', - QueryBuilder::class, - Query::class - ) - ); - - if ($query instanceof QueryBuilder) { - $this->assertGreaterThanOrEqual( - 1, - \count($query->getDQLPart('select')), - "assert there is at least one 'select' part" + $this->assertTrue( + $query instanceof QueryBuilder || $query instanceof NativeQuery, + sprintf( + 'Assert that the returned query is an instance of %s or %s', + QueryBuilder::class, + NativeQuery::class + ) ); - $this->assertGreaterThanOrEqual( - 1, - \count($query->getDQLPart('from')), - "assert there is at least one 'from' part" - ); - } elseif ($query instanceof NativeQuery) { - $this->assertNotEmpty( - $query->getSQL(), - 'check that the SQL query is not empty' - ); + if ($query instanceof QueryBuilder) { + $this->assertGreaterThanOrEqual( + 1, + \count($query->getDQLPart('select')), + "assert there is at least one 'select' part" + ); + + $this->assertGreaterThanOrEqual( + 1, + \count($query->getDQLPart('from')), + "assert there is at least one 'from' part" + ); + } elseif ($query instanceof NativeQuery) { + $this->assertNotEmpty( + $query->getSQL(), + 'check that the SQL query is not empty' + ); + } } } @@ -308,9 +346,11 @@ abstract class AbstractExportTest extends WebTestCase */ public function testRequiredRole() { - $role = $this->getExport()->requiredRole(); + foreach ($this->getExports() as $export) { + $role = $export->requiredRole(); - self::assertIsString($role); + self::assertIsString($role); + } } /** @@ -323,22 +363,23 @@ abstract class AbstractExportTest extends WebTestCase */ public function testSupportsModifier(mixed $modifiers, mixed $acl, mixed $data) { - $export = $this->getExport(); - $query = $export->initiateQuery($modifiers, $acl, $data); + foreach ($this->getExports() as $export) { + $query = $export->initiateQuery($modifiers, $acl, $data); - if ($query instanceof QueryBuilder) { - $this->assertContainsOnly( - 'string', - $export->supportsModifiers(), - true, - 'Test that the `supportsModifiers` method returns only strings' - ); - } elseif ($query instanceof NativeQuery) { - $this->assertTrue( - null === $export->supportsModifiers() - || 0 === \count($export->supportsModifiers()), - 'Test that the `supportsModifier` methods returns null or an empty array' - ); + if ($query instanceof QueryBuilder) { + $this->assertContainsOnly( + 'string', + $export->supportsModifiers(), + true, + 'Test that the `supportsModifiers` method returns only strings' + ); + } elseif ($query instanceof NativeQuery) { + $this->assertTrue( + null === $export->supportsModifiers() + || 0 === \count($export->supportsModifiers()), + 'Test that the `supportsModifier` methods returns null or an empty array' + ); + } } } } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php index a710cccf7..1118b2cc4 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php @@ -23,16 +23,20 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface { protected EntityRepository $repository; + private readonly bool $filterStatsByCenters; public function __construct( EntityManagerInterface $em, + ParameterBagInterface $parameterBag, ) { $this->repository = $em->getRepository(AccompanyingPeriod::class); + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; } public function buildForm(FormBuilderInterface $builder): void @@ -102,15 +106,19 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface ->andWhere('acp.step != :count_acp_step') ->leftJoin('acp.participations', 'acppart') ->leftJoin('acppart.person', 'person') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person + ->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + '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) ' + ) ) - ) - ->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingPeriodWork.php index e1e771222..e274ac5cd 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingPeriodWork.php @@ -22,11 +22,19 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class CountAccompanyingPeriodWork implements ExportInterface, GroupedExportInterface { - public function __construct(protected EntityManagerInterface $em) {} + private readonly bool $filterStatsByCenters; + + public function __construct( + protected EntityManagerInterface $em, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder): void { @@ -95,15 +103,19 @@ class CountAccompanyingPeriodWork implements ExportInterface, GroupedExportInter ->from(AccompanyingPeriod\AccompanyingPeriodWork::class, 'acpw') ->join('acpw.accompanyingPeriod', 'acp') ->join('acp.participations', 'acppart') - ->join('acppart.person', 'person') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person + ->join('acppart.person', 'person'); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + '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) ' + ) ) - ) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } $qb->select('COUNT(DISTINCT acpw.id) as export_result'); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php b/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php index ad32e0a03..0cbe7b3e8 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php @@ -21,11 +21,19 @@ use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class CountEvaluation implements ExportInterface, GroupedExportInterface { - public function __construct(private readonly EntityManagerInterface $entityManager) {} + private readonly bool $filterStatsByCenters; + + public function __construct( + private readonly EntityManagerInterface $entityManager, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) {} @@ -92,15 +100,19 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface ->join('workeval.accompanyingPeriodWork', 'acpw') ->join('acpw.accompanyingPeriod', 'acp') ->join('acp.participations', 'acppart') - ->join('acppart.person', 'person') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person + ->join('acppart.person', 'person'); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + '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) ' + ) ) - ) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php b/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php index 9d4d22085..82a5c4aa4 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php @@ -23,13 +23,21 @@ use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Security\Authorization\HouseholdVoter; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class CountHousehold implements ExportInterface, GroupedExportInterface { private const TR_PREFIX = 'export.export.nb_household_with_course.'; + private readonly bool $filterStatsByCenters; - public function __construct(private readonly EntityManagerInterface $entityManager, private readonly RollingDateConverterInterface $rollingDateConverter) {} + public function __construct( + private readonly EntityManagerInterface $entityManager, + private readonly RollingDateConverterInterface $rollingDateConverter, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -112,21 +120,25 @@ class CountHousehold implements ExportInterface, GroupedExportInterface ->join('person.accompanyingPeriodParticipations', 'acppart') ->join('acppart.accompanyingPeriod', 'acp') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') - ->andWhere( - $qb->expr()->exists( - '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) - ' - ) - ) - ->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)') - ->setParameter('authorized_centers', $centers) ->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date'])); $qb ->select('COUNT(DISTINCT household.id) AS household_export_result') ->addSelect('COUNT(DISTINCT acp.id) AS acp_export_result'); + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + '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) + ' + ) + ) + ->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)') + ->setParameter('authorized_centers', $centers); + } + return $qb; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountPerson.php b/src/Bundle/ChillPersonBundle/Export/Export/CountPerson.php index a9635791a..a1e855b0e 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountPerson.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountPerson.php @@ -20,11 +20,19 @@ use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class CountPerson implements ExportInterface, GroupedExportInterface { - public function __construct(protected PersonRepository $personRepository) {} + private readonly bool $filterStatsByCenters; + + public function __construct( + protected PersonRepository $personRepository, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -94,13 +102,17 @@ class CountPerson implements ExportInterface, GroupedExportInterface $qb = $this->personRepository->createQueryBuilder('person'); - $qb->select('COUNT(DISTINCT person.id) AS export_result') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' + $qb->select('COUNT(DISTINCT person.id) AS export_result'); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' + ) ) - ) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } return $qb; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php b/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php index a582d987f..ef000603a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php @@ -22,16 +22,20 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class CountPersonWithAccompanyingCourse implements ExportInterface, GroupedExportInterface { private readonly EntityRepository $repository; + private readonly bool $filterStatsByCenters; public function __construct( EntityManagerInterface $em, + ParameterBagInterface $parameterBag, ) { $this->repository = $em->getRepository(AccompanyingPeriod::class); + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; } public function buildForm(FormBuilderInterface $builder) @@ -105,11 +109,13 @@ class CountPersonWithAccompanyingCourse implements ExportInterface, GroupedExpor $qb->join('acppart.person', 'person'); } - $qb->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' - ) - )->setParameter('authorized_centers', $centers); + if ($this->filterStatsByCenters) { + $qb->andWhere( + $qb->expr()->exists( + 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' + ) + )->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriod.php index cd6eb2e81..881a38db6 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriod.php @@ -26,15 +26,21 @@ use Chill\PersonBundle\Export\Helper\ListAccompanyingPeriodHelper; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; final readonly class ListAccompanyingPeriod implements ListInterface, GroupedExportInterface { + private bool $filterStatsByCenters; + public function __construct( private EntityManagerInterface $entityManager, private RollingDateConverterInterface $rollingDateConverter, private ListAccompanyingPeriodHelper $listAccompanyingPeriodHelper, - ) {} + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -102,16 +108,20 @@ final readonly class ListAccompanyingPeriod implements ListInterface, GroupedExp $qb ->from(AccompanyingPeriod::class, 'acp') ->andWhere('acp.step != :list_acp_step') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part + ->setParameter('list_acp_step', AccompanyingPeriod::STEP_DRAFT); + + if ($this->filterStatsByCenters) { + $qb + ->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) ' + ) ) - ) - ->setParameter('list_acp_step', AccompanyingPeriod::STEP_DRAFT) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } $this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date'])); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWork.php index 6c9b5d202..81c60bae6 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWork.php @@ -44,6 +44,7 @@ use Chill\ThirdPartyBundle\Export\Helper\LabelThirdPartyHelper; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\QueryBuilder; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterface @@ -78,6 +79,8 @@ class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterfac 'updatedBy', ]; + private readonly bool $filterStatsByCenters; + public function __construct( private readonly EntityManagerInterface $entityManager, private readonly DateTimeHelper $dateTimeHelper, @@ -90,8 +93,11 @@ class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterfac private readonly SocialActionRender $socialActionRender, private readonly RollingDateConverterInterface $rollingDateConverter, private readonly AggregateStringHelper $aggregateStringHelper, - private readonly SocialActionRepository $socialActionRepository - ) {} + private readonly SocialActionRepository $socialActionRepository, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -214,15 +220,19 @@ class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterfac ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') // get participants at the given date ->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person + ->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date'])); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + '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) ' + ) ) - ) - ->setParameter('authorized_centers', $centers) - ->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date'])); + ->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListEvaluation.php b/src/Bundle/ChillPersonBundle/Export/Export/ListEvaluation.php index 653075dbc..6b3eba107 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListEvaluation.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListEvaluation.php @@ -37,6 +37,7 @@ use Chill\PersonBundle\Templating\Entity\SocialIssueRender; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\QueryBuilder; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class ListEvaluation implements ListInterface, GroupedExportInterface @@ -68,7 +69,24 @@ class ListEvaluation implements ListInterface, GroupedExportInterface 'updatedBy', ]; - public function __construct(private readonly EntityManagerInterface $entityManager, private readonly SocialIssueRender $socialIssueRender, private readonly SocialIssueRepository $socialIssueRepository, private readonly SocialActionRender $socialActionRender, private readonly SocialActionRepository $socialActionRepository, private readonly UserHelper $userHelper, private readonly LabelPersonHelper $personHelper, private readonly DateTimeHelper $dateTimeHelper, private readonly TranslatableStringExportLabelHelper $translatableStringExportLabelHelper, private readonly AggregateStringHelper $aggregateStringHelper, private readonly RollingDateConverterInterface $rollingDateConverter) {} + private readonly bool $filterStatsByCenters; + + public function __construct( + private readonly EntityManagerInterface $entityManager, + private readonly SocialIssueRender $socialIssueRender, + private readonly SocialIssueRepository $socialIssueRepository, + private readonly SocialActionRender $socialActionRender, + private readonly SocialActionRepository $socialActionRepository, + private readonly UserHelper $userHelper, + private readonly LabelPersonHelper $personHelper, + private readonly DateTimeHelper $dateTimeHelper, + private readonly TranslatableStringExportLabelHelper $translatableStringExportLabelHelper, + private readonly AggregateStringHelper $aggregateStringHelper, + private readonly RollingDateConverterInterface $rollingDateConverter, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -190,15 +208,19 @@ class ListEvaluation implements ListInterface, GroupedExportInterface ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') // get participants at the given date ->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person + ->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date'])); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + '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) ' + ) ) - ) - ->setParameter('authorized_centers', $centers) - ->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date'])); + ->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListHouseholdInPeriod.php b/src/Bundle/ChillPersonBundle/Export/Export/ListHouseholdInPeriod.php index 2d332969d..46770fab8 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListHouseholdInPeriod.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListHouseholdInPeriod.php @@ -29,6 +29,7 @@ use Chill\PersonBundle\Security\Authorization\HouseholdVoter; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\QueryBuilder; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface @@ -42,14 +43,18 @@ class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface 'compositionComment', 'compositionType', ]; + private readonly bool $filterStatsByCenters; public function __construct( private readonly ExportAddressHelper $addressHelper, private readonly AggregateStringHelper $aggregateStringHelper, private readonly EntityManagerInterface $entityManager, private readonly RollingDateConverterInterface $rollingDateConverter, - private readonly TranslatableStringExportLabelHelper $translatableStringHelper - ) {} + private readonly TranslatableStringExportLabelHelper $translatableStringHelper, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -138,16 +143,20 @@ class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface ->join('person.accompanyingPeriodParticipations', 'acppart') ->join('acppart.accompanyingPeriod', 'acp') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person + ->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)') + ->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date'])); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + '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) ' + ) ) - ) - ->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)') - ->setParameter('authorized_centers', $centers) - ->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date'])); + ->setParameter('authorized_centers', $centers); + } $this->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date'])); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php b/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php index 8beda5ef5..b0e916765 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php @@ -29,6 +29,7 @@ use DateTimeImmutable; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; use PhpOffice\PhpSpreadsheet\Shared\Date; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints\Callback; @@ -40,14 +41,18 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; class ListPerson implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface { private array $slugs = []; + private readonly bool $filterStatsByCenters; public function __construct( private readonly ExportAddressHelper $addressHelper, private readonly CustomFieldProvider $customFieldProvider, private readonly ListPersonHelper $listPersonHelper, private readonly EntityManagerInterface $entityManager, - private readonly TranslatableStringHelper $translatableStringHelper - ) {} + private readonly TranslatableStringHelper $translatableStringHelper, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -184,16 +189,18 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou throw new \Doctrine\DBAL\Exception\InvalidArgumentException('any fields have been checked'); } - $qb = $this->entityManager->createQueryBuilder(); + $qb = $this->entityManager->createQueryBuilder() + ->from(Person::class, 'person'); - $qb - ->from(Person::class, 'person') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.Person\PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + 'SELECT 1 FROM '.Person\PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' + ) ) - ) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } $fields = $data['fields']; diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php index 7cc2a4c35..e638838fb 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php @@ -17,7 +17,9 @@ use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\Helper\ExportAddressHelper; use Chill\MainBundle\Export\ListInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person\PersonCenterHistory; @@ -27,6 +29,7 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter; use DateTimeImmutable; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints\Callback; @@ -37,9 +40,19 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; * * Details of the accompanying period are not included */ -class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface +final readonly class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface { - public function __construct(private readonly ExportAddressHelper $addressHelper, private readonly ListPersonHelper $listPersonHelper, private readonly EntityManagerInterface $entityManager) {} + private bool $filterStatsByCenters; + + public function __construct( + private ExportAddressHelper $addressHelper, + private ListPersonHelper $listPersonHelper, + private EntityManagerInterface $entityManager, + private RollingDateConverterInterface $rollingDateConverter, + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -69,10 +82,9 @@ class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterf ])], ]); - $builder->add('address_date', ChillDateType::class, [ + $builder->add('address_date_rolling', PickRollingDateType::class, [ 'label' => 'Data valid at this date', 'help' => 'Data regarding center, addresses, and so on will be computed at this date', - 'input' => 'datetime_immutable', ]); } @@ -80,7 +92,7 @@ class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterf { $choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS); - return ['fields' => array_values($choices), 'address_date' => new \DateTimeImmutable()]; + return ['fields' => array_values($choices), 'address_date_rolling' => new RollingDate(RollingDate::T_TODAY)]; } public function getAllowedFormattersTypes() @@ -162,16 +174,20 @@ class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterf $qb->from(Person::class, 'person') ->join('person.accompanyingPeriodParticipations', 'acppart') ->join('acppart.accompanyingPeriod', 'acp') - ->andWhere($qb->expr()->neq('acp.step', "'".AccompanyingPeriod::STEP_DRAFT."'")) - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' - ) - )->setParameter('authorized_centers', $centers); + ->andWhere($qb->expr()->neq('acp.step', "'".AccompanyingPeriod::STEP_DRAFT."'")); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' + ) + )->setParameter('authorized_centers', $centers); + } $fields = $data['fields']; - $this->listPersonHelper->addSelect($qb, $fields, $data['address_date']); + $this->listPersonHelper->addSelect($qb, $fields, $this->rollingDateConverter->convert($data['address_date_rolling'])); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php index 22be5ceca..d1cf49a5d 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php @@ -28,6 +28,7 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter; use DateTimeImmutable; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; /** @@ -35,12 +36,17 @@ use Symfony\Component\Form\FormBuilderInterface; */ final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInterface, GroupedExportInterface { + private bool $filterStatsByCenters; + public function __construct( private ListPersonHelper $listPersonHelper, private ListAccompanyingPeriodHelper $listAccompanyingPeriodHelper, private EntityManagerInterface $entityManager, private RollingDateConverterInterface $rollingDateConverter, - ) {} + ParameterBagInterface $parameterBag, + ) { + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; + } public function buildForm(FormBuilderInterface $builder) { @@ -114,12 +120,16 @@ final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInte $qb->from(Person::class, 'person') ->join('person.accompanyingPeriodParticipations', 'acppart') ->join('acppart.accompanyingPeriod', 'acp') - ->andWhere($qb->expr()->neq('acp.step', "'".AccompanyingPeriod::STEP_DRAFT."'")) - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' - ) - )->setParameter('authorized_centers', $centers); + ->andWhere($qb->expr()->neq('acp.step', "'".AccompanyingPeriod::STEP_DRAFT."'")); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' + ) + )->setParameter('authorized_centers', $centers); + } $this->listPersonHelper->addSelect($qb, ListPersonHelper::FIELDS, $this->rollingDateConverter->convert($data['address_date'])); $this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['address_date'])); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php b/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php index 01cc94aa8..58f06ab7e 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php @@ -15,7 +15,9 @@ use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Export\Declarations; @@ -24,28 +26,34 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\FormBuilderInterface; -class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportInterface +final readonly class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportInterface { private readonly EntityRepository $repository; + private bool $filterStatsByCenters; + public function __construct( EntityManagerInterface $em, + private RollingDateConverterInterface $rollingDateConverter, + ParameterBagInterface $parameterBag, ) { $this->repository = $em->getRepository(AccompanyingPeriod::class); + $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center']; } public function buildForm(FormBuilderInterface $builder): void { - $builder->add('closingdate', ChillDateType::class, [ + $builder->add('closingdate_rolling', PickRollingDateType::class, [ 'label' => 'Closingdate to apply', ]); } public function getFormDefaultData(): array { - return ['closingdate' => new \DateTime('now')]; + return ['closingdate_rolling' => new RollingDate(RollingDate::T_TODAY)]; } public function getAllowedFormattersTypes(): array @@ -118,20 +126,24 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn ->addSelect('COUNT(DISTINCT acppart.id) AS count_acppart_export_result') ->addSelect('COUNT(DISTINCT person.id) AS count_pers_export_result') ->addSelect('COUNT(DISTINCT acp.id) AS count_acp_export_result') - ->setParameter('force_closingDate', $data['closingdate']) + ->setParameter('force_closingDate', $this->rollingDateConverter->convert($data['closingdate_rolling'])) ->leftJoin('acp.participations', 'acppart') ->leftJoin('acppart.person', 'person') ->andWhere('acp.step != :count_acp_step') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person + ->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT); + + if ($this->filterStatsByCenters) { + $qb + ->andWhere( + $qb->expr()->exists( + '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) ' + ) ) - ) - ->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT) - ->setParameter('authorized_centers', $centers); + ->setParameter('authorized_centers', $centers); + } AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingCourseTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingCourseTest.php index 2b7f8468c..88803e508 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingCourseTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingCourseTest.php @@ -14,6 +14,7 @@ namespace Export\Export; use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Export\CountAccompanyingCourse; +use Doctrine\ORM\EntityManagerInterface; /** * @internal @@ -22,18 +23,17 @@ use Chill\PersonBundle\Export\Export\CountAccompanyingCourse; */ final class CountAccompanyingCourseTest extends AbstractExportTest { - private CountAccompanyingCourse $export; - protected function setUp(): void { self::bootKernel(); - - $this->export = self::$container->get('chill.person.export.count_accompanyingcourse'); } public function getExport() { - return $this->export; + $em = self::$container->get(EntityManagerInterface::class); + + yield new CountAccompanyingCourse($em, $this->getParameters(true)); + yield new CountAccompanyingCourse($em, $this->getParameters(false)); } public function getFormData(): array diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingPeriodWorkTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingPeriodWorkTest.php index 1ec36a0ab..271f448d6 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingPeriodWorkTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingPeriodWorkTest.php @@ -14,6 +14,7 @@ namespace Export\Export; use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Export\CountAccompanyingPeriodWork; +use Doctrine\ORM\EntityManagerInterface; /** * @internal @@ -33,7 +34,10 @@ final class CountAccompanyingPeriodWorkTest extends AbstractExportTest public function getExport() { - return $this->export; + $em = self::$container->get(EntityManagerInterface::class); + + yield new CountAccompanyingPeriodWork($em, $this->getParameters(true)); + yield new CountAccompanyingPeriodWork($em, $this->getParameters(false)); } public function getFormData(): array diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php index 91640e9a4..758b4d11f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Tests\Export\Export; use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\PersonBundle\Export\Export\CountPerson; +use Chill\PersonBundle\Repository\PersonRepository; /** * Test CountPerson export. @@ -23,18 +24,17 @@ use Chill\PersonBundle\Export\Export\CountPerson; */ final class CountPersonTest extends AbstractExportTest { - private ?object $export = null; - protected function setUp(): void { self::bootKernel(); - - $this->export = self::$container->get(CountPerson::class); } public function getExport() { - return $this->export; + $personRepository = self::$container->get(PersonRepository::class); + + yield new CountPerson($personRepository, $this->getParameters(true)); + yield new CountPerson($personRepository, $this->getParameters(false)); } public function getFormData() diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonWithAccompanyingCourseTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonWithAccompanyingCourseTest.php new file mode 100644 index 000000000..128bf271d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonWithAccompanyingCourseTest.php @@ -0,0 +1,48 @@ +get(EntityManagerInterface::class); + + yield new CountPersonWithAccompanyingCourse($em, $this->getParameters(true)); + yield new CountPersonWithAccompanyingCourse($em, $this->getParameters(false)); + } + + public function getFormData() + { + return [[]]; + } + + public function getModifiersCombination() + { + return [[Declarations::ACP_TYPE]]; + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodTest.php index 0a864050f..a74822584 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodTest.php @@ -11,43 +11,51 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Export; -use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Repository\CenterRepositoryInterface; use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; +use Chill\MainBundle\Test\Export\AbstractExportTest; +use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Export\ListAccompanyingPeriod; -use Doctrine\ORM\AbstractQuery; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Chill\PersonBundle\Export\Helper\ListAccompanyingPeriodHelper; +use Doctrine\ORM\EntityManagerInterface; /** * @internal * * @coversNothing */ -class ListAccompanyingPeriodTest extends KernelTestCase +class ListAccompanyingPeriodTest extends AbstractExportTest { - private ListAccompanyingPeriod $listAccompanyingPeriod; + private readonly ListAccompanyingPeriod $listAccompanyingPeriod; - private CenterRepositoryInterface $centerRepository; + private readonly CenterRepositoryInterface $centerRepository; protected function setUp(): void { parent::setUp(); self::bootKernel(); - - $this->listAccompanyingPeriod = self::$container->get(ListAccompanyingPeriod::class); - $this->centerRepository = self::$container->get(CenterRepositoryInterface::class); } - public function testQuery(): void + public function getExport() { - $centers = $this->centerRepository->findAll(); + $em = self::$container->get(EntityManagerInterface::class); + $rollingDateConverter = self::$container->get(RollingDateConverterInterface::class); + $listAccompanyingPeriodHelper = self::$container->get(ListAccompanyingPeriodHelper::class); - $query = $this->listAccompanyingPeriod->initiateQuery([], array_map(fn (Center $c) => ['center' => $c], $centers), $exportOpts = ['calc_date' => new RollingDate(RollingDate::T_TODAY)]); + yield new ListAccompanyingPeriod($em, $rollingDateConverter, $listAccompanyingPeriodHelper, $this->getParameters(true)); + yield new ListAccompanyingPeriod($em, $rollingDateConverter, $listAccompanyingPeriodHelper, $this->getParameters(false)); + } - $query->setMaxResults(1); + public function getFormData() + { + return [ + ['calc_date' => new RollingDate(RollingDate::T_TODAY)], + ]; + } - $actual = $query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY); - - self::assertIsArray($actual); + public function getModifiersCombination() + { + return [[Declarations::ACP_TYPE]]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodWorkTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodWorkTest.php index 08fa5141e..ab8ca7c38 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodWorkTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodWorkTest.php @@ -11,40 +11,93 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Export; -use Chill\MainBundle\Entity\Center; -use Chill\MainBundle\Repository\CenterRepositoryInterface; +use Chill\MainBundle\Export\Helper\AggregateStringHelper; +use Chill\MainBundle\Export\Helper\DateTimeHelper; +use Chill\MainBundle\Export\Helper\TranslatableStringExportLabelHelper; +use Chill\MainBundle\Export\Helper\UserHelper; use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; +use Chill\MainBundle\Test\Export\AbstractExportTest; +use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Export\ListAccompanyingPeriodWork; -use Doctrine\ORM\AbstractQuery; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Chill\PersonBundle\Export\Helper\LabelPersonHelper; +use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository; +use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository; +use Chill\PersonBundle\Templating\Entity\SocialActionRender; +use Chill\PersonBundle\Templating\Entity\SocialIssueRender; +use Chill\ThirdPartyBundle\Export\Helper\LabelThirdPartyHelper; +use Doctrine\ORM\EntityManagerInterface; /** * @internal * * @coversNothing */ -class ListAccompanyingPeriodWorkTest extends KernelTestCase +class ListAccompanyingPeriodWorkTest extends AbstractExportTest { - private ListAccompanyingPeriodWork $listAccompanyingPeriodWork; - - private CenterRepositoryInterface $centerRepository; - protected function setUp(): void { parent::setUp(); self::bootKernel(); - - $this->listAccompanyingPeriodWork = self::$container->get(ListAccompanyingPeriodWork::class); - $this->centerRepository = self::$container->get(CenterRepositoryInterface::class); } - public function testQuery(): void + public function getExport() { - $centers = $this->centerRepository->findAll(); + $entityManager = self::$container->get(EntityManagerInterface::class); + $dateTimeHelper = self::$container->get(DateTimeHelper::class); + $userHelper = self::$container->get(UserHelper::class); + $personHelper = self::$container->get(LabelPersonHelper::class); + $thirdPartyHelper = self::$container->get(LabelThirdPartyHelper::class); + $translatableStringExportLabelHelper = self::$container->get(TranslatableStringExportLabelHelper::class); + $socialIssueRender = self::$container->get(SocialIssueRender::class); + $socialIssueRepository = self::$container->get(SocialIssueRepository::class); + $socialActionRender = self::$container->get(SocialActionRender::class); + $rollingDateConverter = self::$container->get(RollingDateConverterInterface::class); + $aggregateStringHelper = self::$container->get(AggregateStringHelper::class); + $socialActionRepository = self::$container->get(SocialActionRepository::class); - $query = $this->listAccompanyingPeriodWork->initiateQuery([], array_map(fn (Center $c) => ['center' => $c], $centers), ['calc_date' => new RollingDate(RollingDate::T_TODAY)]); - $query->setMaxResults(1); + yield new ListAccompanyingPeriodWork( + $entityManager, + $dateTimeHelper, + $userHelper, + $personHelper, + $thirdPartyHelper, + $translatableStringExportLabelHelper, + $socialIssueRender, + $socialIssueRepository, + $socialActionRender, + $rollingDateConverter, + $aggregateStringHelper, + $socialActionRepository, + $this->getParameters(true), + ); - self::assertIsArray($query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY)); + yield new ListAccompanyingPeriodWork( + $entityManager, + $dateTimeHelper, + $userHelper, + $personHelper, + $thirdPartyHelper, + $translatableStringExportLabelHelper, + $socialIssueRender, + $socialIssueRepository, + $socialActionRender, + $rollingDateConverter, + $aggregateStringHelper, + $socialActionRepository, + $this->getParameters(false), + ); + } + + public function getFormData() + { + return [ + ['calc_date' => new RollingDate(RollingDate::T_TODAY)], + ]; + } + + public function getModifiersCombination() + { + return [[Declarations::ACP_TYPE]]; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListEvaluationTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListEvaluationTest.php index 7015fae11..08920881e 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListEvaluationTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListEvaluationTest.php @@ -12,18 +12,30 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Export; use Chill\MainBundle\Entity\Center; +use Chill\MainBundle\Export\Helper\AggregateStringHelper; +use Chill\MainBundle\Export\Helper\DateTimeHelper; +use Chill\MainBundle\Export\Helper\TranslatableStringExportLabelHelper; +use Chill\MainBundle\Export\Helper\UserHelper; use Chill\MainBundle\Repository\CenterRepositoryInterface; use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; +use Chill\MainBundle\Test\Export\AbstractExportTest; +use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Export\ListEvaluation; +use Chill\PersonBundle\Export\Helper\LabelPersonHelper; +use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository; +use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository; +use Chill\PersonBundle\Templating\Entity\SocialActionRender; +use Chill\PersonBundle\Templating\Entity\SocialIssueRender; use Doctrine\ORM\AbstractQuery; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Doctrine\ORM\EntityManagerInterface; /** * @internal * * @coversNothing */ -class ListEvaluationTest extends KernelTestCase +class ListEvaluationTest extends AbstractExportTest { private ListEvaluation $listEvaluation; @@ -38,6 +50,61 @@ class ListEvaluationTest extends KernelTestCase $this->centerRepository = self::$container->get(CenterRepositoryInterface::class); } + public function getExport() + { + $entityManager = self::$container->get(EntityManagerInterface::class); + $dateTimeHelper = self::$container->get(DateTimeHelper::class); + $userHelper = self::$container->get(UserHelper::class); + $personHelper = self::$container->get(LabelPersonHelper::class); + $translatableStringExportLabelHelper = self::$container->get(TranslatableStringExportLabelHelper::class); + $socialIssueRender = self::$container->get(SocialIssueRender::class); + $socialIssueRepository = self::$container->get(SocialIssueRepository::class); + $socialActionRender = self::$container->get(SocialActionRender::class); + $rollingDateConverter = self::$container->get(RollingDateConverterInterface::class); + $aggregateStringHelper = self::$container->get(AggregateStringHelper::class); + $socialActionRepository = self::$container->get(SocialActionRepository::class); + + yield new ListEvaluation( + $entityManager, + $socialIssueRender, + $socialIssueRepository, + $socialActionRender, + $socialActionRepository, + $userHelper, + $personHelper, + $dateTimeHelper, + $translatableStringExportLabelHelper, + $aggregateStringHelper, + $rollingDateConverter, + $this->getParameters(true), + ); + + yield new ListEvaluation( + $entityManager, + $socialIssueRender, + $socialIssueRepository, + $socialActionRender, + $socialActionRepository, + $userHelper, + $personHelper, + $dateTimeHelper, + $translatableStringExportLabelHelper, + $aggregateStringHelper, + $rollingDateConverter, + $this->getParameters(false), + ); + } + + public function getFormData() + { + return [['calc_date' => new RollingDate(RollingDate::T_TODAY)]]; + } + + public function getModifiersCombination() + { + return [[Declarations::ACP_TYPE]]; + } + public function testQuery(): void { $centers = $this->centerRepository->findAll(); diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListHouseholdInPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListHouseholdInPeriodTest.php new file mode 100644 index 000000000..929fdc829 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListHouseholdInPeriodTest.php @@ -0,0 +1,72 @@ +get(ExportAddressHelper::class); + $aggregateStringHelper = self::$container->get(AggregateStringHelper::class); + $entityManager = self::$container->get(EntityManagerInterface::class); + $rollingDateConverter = self::$container->get(RollingDateConverterInterface::class); + $translatableStringHelper = self::$container->get(TranslatableStringExportLabelHelper::class); + + yield new ListHouseholdInPeriod( + $addressHelper, + $aggregateStringHelper, + $entityManager, + $rollingDateConverter, + $translatableStringHelper, + $this->getParameters(true), + ); + + yield new ListHouseholdInPeriod( + $addressHelper, + $aggregateStringHelper, + $entityManager, + $rollingDateConverter, + $translatableStringHelper, + $this->getParameters(false), + ); + } + + public function getFormData() + { + return [['calc_date' => new RollingDate(RollingDate::T_TODAY)]]; + } + + public function getModifiersCombination() + { + return [[Declarations::PERSON_TYPE]]; + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonHavingAccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonHavingAccompanyingPeriodTest.php new file mode 100644 index 000000000..c050779e2 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonHavingAccompanyingPeriodTest.php @@ -0,0 +1,69 @@ +get(ExportAddressHelper::class); + $listPersonHelper = self::$container->get(ListPersonHelper::class); + $entityManager = self::$container->get(EntityManagerInterface::class); + $rollingDateconverter = self::$container->get(RollingDateConverterInterface::class); + + yield new ListPersonHavingAccompanyingPeriod( + $addressHelper, + $listPersonHelper, + $entityManager, + $rollingDateconverter, + $this->getParameters(true), + ); + + yield new ListPersonHavingAccompanyingPeriod( + $addressHelper, + $listPersonHelper, + $entityManager, + $rollingDateconverter, + $this->getParameters(false), + ); + } + + public function getFormData() + { + return [['address_date_rolling' => new RollingDate(RollingDate::T_TODAY), 'fields' => ListPersonHelper::FIELDS]]; + } + + public function getModifiersCombination() + { + return [[Declarations::PERSON_TYPE, Declarations::ACP_TYPE]]; + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php index 11937c216..b398d1c91 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php @@ -11,8 +11,13 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Export; +use Chill\CustomFieldsBundle\Service\CustomFieldProvider; +use Chill\MainBundle\Export\Helper\ExportAddressHelper; +use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\PersonBundle\Export\Export\ListPerson; +use Chill\PersonBundle\Export\Helper\ListPersonHelper; +use Doctrine\ORM\EntityManagerInterface; use Prophecy\PhpUnit\ProphecyTrait; /** @@ -45,7 +50,29 @@ final class ListPersonTest extends AbstractExportTest public function getExport() { - return $this->export; + $addressHelper = self::$container->get(ExportAddressHelper::class); + $customFieldProvider = self::$container->get(CustomFieldProvider::class); + $listPersonHelper = self::$container->get(ListPersonHelper::class); + $entityManager = self::$container->get(EntityManagerInterface::class); + $translatableStringHelper = self::$container->get(TranslatableStringHelper::class); + + yield new ListPerson( + $addressHelper, + $customFieldProvider, + $listPersonHelper, + $entityManager, + $translatableStringHelper, + $this->getParameters(true), + ); + + yield new ListPerson( + $addressHelper, + $customFieldProvider, + $listPersonHelper, + $entityManager, + $translatableStringHelper, + $this->getParameters(false), + ); } public function getFormData(): iterable diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonWithAccompanyingPeriodDetailsTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonWithAccompanyingPeriodDetailsTest.php new file mode 100644 index 000000000..aba208df9 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonWithAccompanyingPeriodDetailsTest.php @@ -0,0 +1,73 @@ +get(ListPersonHelper::class); + $listAccompanyingPeriodHelper = self::$container->get(ListAccompanyingPeriodHelper::class); + $entityManager = self::$container->get(EntityManagerInterface::class); + $rollingDateConverter = self::$container->get(RollingDateConverterInterface::class); + + yield new ListPersonWithAccompanyingPeriodDetails( + $listPersonHelper, + $listAccompanyingPeriodHelper, + $entityManager, + $rollingDateConverter, + $this->getParameters(true), + ); + + yield new ListPersonWithAccompanyingPeriodDetails( + $listPersonHelper, + $listAccompanyingPeriodHelper, + $entityManager, + $rollingDateConverter, + $this->getParameters(false), + ); + } + + public function getFormData() + { + return [ + ['address_date' => new RollingDate(RollingDate::T_TODAY)], + ]; + } + + public function getModifiersCombination() + { + return [ + [Declarations::PERSON_TYPE, Declarations::ACP_TYPE], + ]; + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/StatAccompanyingCourseDurationTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/StatAccompanyingCourseDurationTest.php index a5ce35a7a..bf06466c6 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/StatAccompanyingCourseDurationTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/StatAccompanyingCourseDurationTest.php @@ -11,9 +11,12 @@ declare(strict_types=1); namespace Export\Export; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Export\StatAccompanyingCourseDuration; +use Doctrine\ORM\EntityManagerInterface; /** * @internal @@ -33,13 +36,17 @@ final class StatAccompanyingCourseDurationTest extends AbstractExportTest public function getExport() { - return $this->export; + $em = self::$container->get(EntityManagerInterface::class); + $rollingDateconverter = self::$container->get(RollingDateConverterInterface::class); + + yield new StatAccompanyingCourseDuration($em, $rollingDateconverter, $this->getParameters(true)); + yield new StatAccompanyingCourseDuration($em, $rollingDateconverter, $this->getParameters(false)); } public function getFormData(): array { return [ - ['closingdate' => \DateTime::createFromFormat('Y-m-d', '2022-06-30')], + ['closingdate_rolling' => new RollingDate(RollingDate::T_TODAY)], ]; }