From 6921e4a40d079b82ab34004256456b9df86a4400 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 3 Aug 2022 15:20:34 +0200 Subject: [PATCH 1/6] exports: add new RequestorFilter --- .../Export/Filter/RequestorFilter.php | 153 ++++++++++++++++++ .../services/exports_accompanying_period.yaml | 7 + .../translations/messages.fr.yml | 8 + 3 files changed, 168 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/RequestorFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/RequestorFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/RequestorFilter.php new file mode 100644 index 000000000..ca2173e5a --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/RequestorFilter.php @@ -0,0 +1,153 @@ + 'participation', + 'is other person' => 'other_person', + 'is thirdparty' => 'thirdparty', + 'no requestor' => 'no_requestor', + ]; + + private const DEFAULT_CHOICE = 'participation'; + + protected TranslatorInterface $translator; + + protected EntityManagerInterface $em; + + public function __construct( + TranslatorInterface $translator, + EntityManagerInterface $em + ) { + $this->translator = $translator; + $this->em = $em; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_choices', ChoiceType::class, [ + 'choices' => self::REQUESTOR_CHOICES, + 'multiple' => false, + 'expanded' => true, + 'empty_data' => self::DEFAULT_CHOICE, + 'data' => self::DEFAULT_CHOICE, + ]); + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filter by requestor'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string'): array + { + $choice = array_flip(self::REQUESTOR_CHOICES)[$data['accepted_choices']]; + + return ['Filtered by requestor: only %choice%', [ + '%choice%' => $this->translator->trans($choice) + ]]; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + + switch ($data['accepted_choices']) { + case 'participation': + + $qb->join('acp.participations', 'part'); + + $clause = $qb->expr()->andX( + $qb->expr()->isNotNull('acp.requestorPerson'), + $qb->expr()->eq('acp.requestorPerson', 'part.person') + ); + break; + + case 'other_person': + + $expr = $this->em->getExpressionBuilder(); + + $qb->join('acp.participations','part'); + + $clause = $expr->andX( + $expr->isNotNull('acp.requestorPerson'), + $expr->notIn('acp.requestorPerson', + + // subquery + $this->em->createQueryBuilder() + ->select('identity(acp2.requestorPerson)') + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp2') + ->join('acp2.participations', 'part2') + ->where($expr->eq('acp2.requestorPerson', 'part2.person')) + ->getDQL() + + ) + ); + break; + + case 'thirdparty': + + $clause = $qb->expr()->isNotNull('acp.requestorThirdParty'); + break; + + case 'no_requestor': + + $clause = $qb->expr()->andX( + $qb->expr()->isNull('acp.requestorPerson'), + $qb->expr()->isNull('acp.requestorThirdParty') + ); + break; + + default: + throw new \Exception('Uncaught choice exception'); + } + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml index 62ad99b97..b715605af 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -102,6 +102,13 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_administrative_location_filter } + chill.person.export.filter_requestor: + class: Chill\PersonBundle\Export\Filter\RequestorFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_requestor_filter } + chill.person.export.filter_confidential: class: Chill\PersonBundle\Export\Filter\ConfidentialFilter autowire: true diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index f613b09da..bdd70bee4 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -418,6 +418,14 @@ Filter by administrative location: Filtrer par localisation administrative Accepted locations: Localisations administratives "Filtered by administratives locations: only %locations%": "Filtré par localisation administrative: uniquement %locations%" +Filter by requestor: Filtrer les parcours selon la présence du demandeur au sein des usagers concernés +Accepted choices: '' +is person concerned: Le demandeur est un usager concerné +is other person: Le demandeur est un autre usager +is thirdparty: Le demandeur est un tiers +no requestor: Il n'y a pas de demandeur +"Filtered by requestor: only %choice%": "Filtré par présence du demandeur au sein des usagers concernés: uniquement si %choice%" + Filter by confidential: Filtrer par confidentialité Accepted confidentials: '' is confidential: le parcours est confidentiel From 2413c986edc3c286a5dbd97fc60ba39e21a724bd Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 3 Aug 2022 13:34:06 +0200 Subject: [PATCH 2/6] exports: add a new GeographicUnitStat Filter (wip) --- .../Filter/GeographicalUnitStatFilter.php | 101 ++++++++++++++++++ .../services/exports_accompanying_period.yaml | 7 ++ 2 files changed, 108 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php new file mode 100644 index 000000000..0375846e6 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php @@ -0,0 +1,101 @@ + 'territoire', + // TODO not yet implemented: https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/626 + ]; + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder + ->add('date', ChillDateType::class, [ + 'data' => new \DateTime(), + ]) + ->add('accepted_loctype', ChoiceType::class, [ + 'choices' => self::LOCTYPE, + 'multiple' => false, + 'expanded' => true, + ]) + ; + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filter by geographic unit'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string'): array + { + return ['Filtered by geographic unit: only %date%', [ + '%date%' => $data['date']->format('d-m-Y'), + ]]; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->eq(1, 1); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('date', $data['date'], Types::DATE_MUTABLE); + $qb->setParameter('loctype', $data['accepted_loctype']); + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml index b715605af..7ab97f20f 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -60,6 +60,13 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_step_filter } + chill.person.export.filter_geographicalunitstat: + class: Chill\PersonBundle\Export\Filter\GeographicalUnitStatFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_geographicalunitstat_filter } + chill.person.export.filter_socialaction: class: Chill\PersonBundle\Export\Filter\SocialActionFilter autowire: true From e3743d3593a9b20ce2490385aa758506cd4db462 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 1 Aug 2022 10:49:02 +0200 Subject: [PATCH 3/6] tests new filters ReferrerFilter and OpenBetweenDatesFilter (wip.. test failed) --- .../Test/Export/AbstractFilterTest.php | 2 +- .../Export/Filter/ReferrerFilter.php | 4 +- .../Filter/OpenBetweenDatesFilterTest.php | 66 +++++++++++++++ .../Export/Filter/ReferrerFilterTest.php | 82 +++++++++++++++++++ 4 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/OpenBetweenDatesFilterTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/ReferrerFilterTest.php diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php index 34869c30b..bef4fd200 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractFilterTest.php @@ -37,7 +37,7 @@ abstract class AbstractFilterTest extends KernelTestCase protected function setUp(): void { - $$this->prophet = $this->getProphet(); + $this->prophet = $this->getProphet(); } public function dataProviderAlterQuery() diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php index e46b20592..bac2656c6 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php @@ -48,7 +48,7 @@ class ReferrerFilter implements FilterInterface /** * @inheritDoc */ - public function describeAction($data, $format = 'string') + public function describeAction($data, $format = 'string'): array { $users = []; @@ -116,7 +116,7 @@ class ReferrerFilter implements FilterInterface /** * @inheritDoc */ - public function applyOn() + public function applyOn(): string { return Declarations::ACP_SHARED; } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/OpenBetweenDatesFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/OpenBetweenDatesFilterTest.php new file mode 100644 index 000000000..ccb7e38da --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/OpenBetweenDatesFilterTest.php @@ -0,0 +1,66 @@ +prophesize(); + + $request->willExtend(Request::class); + $request->getLocale()->willReturn('fr'); + + $this->filter = self::$container->get('chill.person.export.filter_openbetweendates'); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData(): array + { + return [ + [ + 'date_from' => \DateTime::createFromFormat('Y-m-d', '2022-05-01'), + 'date_to' => \DateTime::createFromFormat('Y-m-d', '2022-06-01'), + ], + ]; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders(): array + { + if (null === self::$kernel) { + self::bootKernel(); + } + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->select('acp.id'), + ]; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ReferrerFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ReferrerFilterTest.php new file mode 100644 index 000000000..ec84c7027 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ReferrerFilterTest.php @@ -0,0 +1,82 @@ +prophesize(); + + $request->willExtend(Request::class); + $request->getLocale()->willReturn('fr'); + + $this->filter = self::$container->get('chill.person.export.filter_referrer'); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData(): array + { + $em = self::$container->get(EntityManagerInterface::class); + + $array = $em->createQueryBuilder() + ->from(User::class, 'u') + ->select('u') + ->getQuery() + ->getResult(); + + $data = []; + + foreach($array as $u) { + $data[] = ['accepted_referrers' => $u]; + } + + return $data; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders(): array + { + if (null === self::$kernel) { + self::bootKernel(); + } + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->select('acp.id'), + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod\AccompanyingPeriodWork', 'acpw') + ->select('acpw.id'), + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod\AccompanyingPeriodWork', 'acpw') + ->join('acpw.referrers', 'r') + ->select('r.id'), + ]; + } +} \ No newline at end of file From 28599adf4824aa9c76f319c56257f14f6b9c5c20 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 1 Aug 2022 11:37:41 +0200 Subject: [PATCH 4/6] tests on new ActiveOnDate and ActiveOneDayBetweenDates filters --- .../Export/Filter/ActiveOnDateFilterTest.php | 65 ++++++++++++++++++ .../ActiveOneDayBetweenDatesFilterTest.php | 66 +++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActiveOnDateFilterTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActiveOneDayBetweenDatesFilterTest.php diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActiveOnDateFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActiveOnDateFilterTest.php new file mode 100644 index 000000000..b66de0f28 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActiveOnDateFilterTest.php @@ -0,0 +1,65 @@ +prophesize(); + + $request->willExtend(Request::class); + $request->getLocale()->willReturn('fr'); + + $this->filter = self::$container->get('chill.person.export.filter_activeondate'); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData(): array + { + return [ + [ + 'on_date' => \DateTime::createFromFormat('Y-m-d', '2022-05-01'), + ], + ]; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders(): array + { + if (null === self::$kernel) { + self::bootKernel(); + } + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->select('acp.id'), + ]; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActiveOneDayBetweenDatesFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActiveOneDayBetweenDatesFilterTest.php new file mode 100644 index 000000000..051db8635 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActiveOneDayBetweenDatesFilterTest.php @@ -0,0 +1,66 @@ +prophesize(); + + $request->willExtend(Request::class); + $request->getLocale()->willReturn('fr'); + + $this->filter = self::$container->get('chill.person.export.filter_activeonedaybetweendates'); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData(): array + { + return [ + [ + 'date_from' => \DateTime::createFromFormat('Y-m-d', '2022-05-01'), + 'date_to' => \DateTime::createFromFormat('Y-m-d', '2022-06-01'), + ], + ]; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders(): array + { + if (null === self::$kernel) { + self::bootKernel(); + } + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->select('acp.id'), + ]; + } +} \ No newline at end of file From ea1a53ed377123bb44c91dc8b1a4891c38b0c7ac Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 4 Aug 2022 09:15:05 +0200 Subject: [PATCH 5/6] tests: add missing FilterTest --- .../Filter/GeographicalUnitStatFilter.php | 2 +- .../Export/Filter/ActivityTypeFilterTest.php | 77 +++++++++++++++++++ .../AdministrativeLocationFilterTest.php | 76 ++++++++++++++++++ .../Export/Filter/EvaluationFilterTest.php | 76 ++++++++++++++++++ .../Filter/GeographicalUnitStatFilterTest.php | 66 ++++++++++++++++ .../Export/Filter/RequestorFilterTest.php | 67 ++++++++++++++++ .../Export/Filter/SocialActionFilterTest.php | 76 ++++++++++++++++++ 7 files changed, 439 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActivityTypeFilterTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/AdministrativeLocationFilterTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilterTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/GeographicalUnitStatFilterTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/RequestorFilterTest.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialActionFilterTest.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php index 0375846e6..c06325265 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php @@ -25,7 +25,7 @@ class GeographicalUnitStatFilter implements FilterInterface { private const LOCTYPE = [ - 'center' => 'territoire', + 'center' => 'center', // TODO not yet implemented: https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/626 ]; diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActivityTypeFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActivityTypeFilterTest.php new file mode 100644 index 000000000..315592ee9 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/ActivityTypeFilterTest.php @@ -0,0 +1,77 @@ +prophesize(); + + $request->willExtend(Request::class); + $request->getLocale()->willReturn('fr'); + + $this->filter = self::$container->get('chill.person.export.filter_activitytype'); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData(): array + { + + $em = self::$container->get(EntityManagerInterface::class); + + $array = $em->createQueryBuilder() + ->from(ActivityType::class, 'at') + ->select('at') + ->getQuery() + ->getResult(); + + $data = []; + + foreach($array as $t) { + $data[] = ['accepted_activitytypes' => $t]; + } + + return $data; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders(): array + { + if (null === self::$kernel) { + self::bootKernel(); + } + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->select('acp.id'), + ]; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AdministrativeLocationFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AdministrativeLocationFilterTest.php new file mode 100644 index 000000000..f974919aa --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AdministrativeLocationFilterTest.php @@ -0,0 +1,76 @@ +prophesize(); + + $request->willExtend(Request::class); + $request->getLocale()->willReturn('fr'); + + $this->filter = self::$container->get('chill.person.export.filter_administrative_location'); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData(): array + { + $em = self::$container->get(EntityManagerInterface::class); + + $array = $em->createQueryBuilder() + ->from(Location::class, 'l') + ->select('l') + ->getQuery() + ->getResult(); + + $data = []; + + foreach($array as $l) { + $data[] = ['accepted_locations' => $l]; + } + + return $data; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders(): array + { + if (null === self::$kernel) { + self::bootKernel(); + } + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->select('acp.id'), + ]; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilterTest.php new file mode 100644 index 000000000..310fde2c9 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilterTest.php @@ -0,0 +1,76 @@ +prophesize(); + + $request->willExtend(Request::class); + $request->getLocale()->willReturn('fr'); + + $this->filter = self::$container->get('chill.person.export.filter_evaluation'); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData(): array + { + $em = self::$container->get(EntityManagerInterface::class); + + $array = $em->createQueryBuilder() + ->from(Evaluation::class, 'ev') + ->select('ev') + ->getQuery() + ->getResult(); + + $data = []; + + foreach($array as $e) { + $data[] = ['accepted_evaluations' => $e]; + } + + return $data; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders(): array + { + if (null === self::$kernel) { + self::bootKernel(); + } + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->select('acp.id'), + ]; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/GeographicalUnitStatFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/GeographicalUnitStatFilterTest.php new file mode 100644 index 000000000..8a205e9ac --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/GeographicalUnitStatFilterTest.php @@ -0,0 +1,66 @@ +prophesize(); + + $request->willExtend(Request::class); + $request->getLocale()->willReturn('fr'); + + $this->filter = self::$container->get('chill.person.export.filter_geographicalunitstat'); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData(): array + { + return [ + [ + 'date' => \DateTime::createFromFormat('Y-m-d', '2022-05-01'), + 'accepted_loctype' => 'center' + ], + ]; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders(): array + { + if (null === self::$kernel) { + self::bootKernel(); + } + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->select('acp.id'), + ]; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/RequestorFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/RequestorFilterTest.php new file mode 100644 index 000000000..f8b01aea1 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/RequestorFilterTest.php @@ -0,0 +1,67 @@ +prophesize(); + + $request->willExtend(Request::class); + $request->getLocale()->willReturn('fr'); + + $this->filter = self::$container->get('chill.person.export.filter_requestor'); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData(): array + { + return [ + ['accepted_choices' => 'participation'], + ['accepted_choices' => 'other_person'], + ['accepted_choices' => 'thirdparty'], + ['accepted_choices' => 'no_requestor'], + ]; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders(): array + { + if (null === self::$kernel) { + self::bootKernel(); + } + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->select('acp.id'), + ]; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialActionFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialActionFilterTest.php new file mode 100644 index 000000000..6de54c23a --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialActionFilterTest.php @@ -0,0 +1,76 @@ +prophesize(); + + $request->willExtend(Request::class); + $request->getLocale()->willReturn('fr'); + + $this->filter = self::$container->get('chill.person.export.filter_socialaction'); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData(): array + { + $em = self::$container->get(EntityManagerInterface::class); + + $array = $em->createQueryBuilder() + ->from(SocialAction::class, 'sa') + ->select('sa') + ->getQuery() + ->getResult(); + + $data = []; + + foreach($array as $a) { + $data[] = ['accepted_socialactions' => $a]; + } + + return $data; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders(): array + { + if (null === self::$kernel) { + self::bootKernel(); + } + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->from('ChillPersonBundle:AccompanyingPeriod', 'acp') + ->select('acp.id'), + ]; + } +} \ No newline at end of file From 43d45a5d04f197b2439a282795ee8a729d571274 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 4 Aug 2022 11:30:52 +0200 Subject: [PATCH 6/6] tests: fix missing use statement --- .../Tests/Export/Aggregator/ActionTypeAggregatorTest.php | 1 + .../Tests/Export/Aggregator/GoalAggregatorTest.php | 1 + .../Tests/Export/Aggregator/ReferrerAggregatorTest.php | 1 + .../Tests/Export/Aggregator/ResultAggregatorTest.php | 1 + 4 files changed, 4 insertions(+) diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ActionTypeAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ActionTypeAggregatorTest.php index 1f5585281..235545e0f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ActionTypeAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ActionTypeAggregatorTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Aggregator; use Chill\MainBundle\Test\Export\AbstractAggregatorTest; +use Chill\PersonBundle\Export\Aggregator\ActionTypeAggregator; /** * @internal diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/GoalAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/GoalAggregatorTest.php index ca1fa9417..050b8ad5a 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/GoalAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/GoalAggregatorTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Aggregator; use Chill\MainBundle\Test\Export\AbstractAggregatorTest; +use Chill\PersonBundle\Export\Aggregator\GoalAggregator; /** * @internal diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ReferrerAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ReferrerAggregatorTest.php index f1aa07190..e4e0eace8 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ReferrerAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ReferrerAggregatorTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Aggregator; use Chill\MainBundle\Test\Export\AbstractAggregatorTest; +use Chill\PersonBundle\Export\Aggregator\ReferrerAggregator; /** * @internal diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ResultAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ResultAggregatorTest.php index f5080e488..3112fc2d4 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ResultAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/ResultAggregatorTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Aggregator; use Chill\MainBundle\Test\Export\AbstractAggregatorTest; +use Chill\PersonBundle\Export\Aggregator\ResultAggregator; /** * @internal