From 9a2af662c0b28eb3f46566831c1018999c180049 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 9 Aug 2022 16:13:24 +0200 Subject: [PATCH 1/9] use translatablestringhelper --- .../PersonAggregators/MaritalStatusAggregator.php | 12 +++++++----- .../SocialWorkAggregators/ActionTypeAggregator.php | 9 +++++---- .../SocialWorkAggregators/GoalAggregator.php | 8 ++++++-- .../SocialWorkAggregators/ResultAggregator.php | 6 +++--- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/MaritalStatusAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/MaritalStatusAggregator.php index ec15be45f..3d4c1f7cd 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/MaritalStatusAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/MaritalStatusAggregator.php @@ -12,21 +12,23 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators; use Chill\MainBundle\Export\AggregatorInterface; -use Chill\PersonBundle\Entity\Person; +use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Repository\MaritalStatusRepository; use Doctrine\ORM\QueryBuilder; -use LogicException; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Contracts\Translation\TranslatorInterface; + final class MaritalStatusAggregator implements AggregatorInterface { private MaritalStatusRepository $maritalStatusRepository; - public function __construct(MaritalStatusRepository $maritalStatusRepository) + private TranslatableStringHelper $translatableStringHelper; + + public function __construct(MaritalStatusRepository $maritalStatusRepository, TranslatableStringHelper $translatableStringHelper) { $this->maritalStatusRepository = $maritalStatusRepository; + $this->translatableStringHelper = $translatableStringHelper; } public function addRole() @@ -66,7 +68,7 @@ final class MaritalStatusAggregator implements AggregatorInterface $g = $this->maritalStatusRepository->find($value); - return $g->getName()['fr']; + return $this->translatableStringHelper->localize($g->getName()); }; } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php index 2567ea378..d8f485561 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php @@ -12,9 +12,9 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators; use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository; -use Chill\PersonBundle\Templating\Entity\SocialActionRender; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -22,11 +22,12 @@ final class ActionTypeAggregator implements AggregatorInterface { private SocialActionRepository $socialActionRepository; - private SocialActionRender $socialActionRender; + private TranslatableStringHelper $translatableStringHelper; - public function __construct(SocialActionRepository $socialActionRepository) + public function __construct(SocialActionRepository $socialActionRepository, TranslatableStringHelper $translatableStringHelper) { $this->socialActionRepository = $socialActionRepository; + $this->translatableStringHelper = $translatableStringHelper; } public function addRole() @@ -69,7 +70,7 @@ final class ActionTypeAggregator implements AggregatorInterface $sa = $this->socialActionRepository->find($value); - return $sa->getTitle()['fr']; + return $this->translatableStringHelper->localize($sa->getTitle()); }; } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php index d3b277a16..cb908ef3e 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators; use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Repository\SocialWork\GoalRepository; use Doctrine\ORM\QueryBuilder; @@ -21,9 +22,12 @@ final class GoalAggregator implements AggregatorInterface { private GoalRepository $goalRepository; - public function __construct(GoalRepository $goalRepository) + private TranslatableStringHelper $translatableStringHelper; + + public function __construct(GoalRepository $goalRepository, TranslatableStringHelper $translatableStringHelper) { $this->goalRepository = $goalRepository; + $this->translatableStringHelper = $translatableStringHelper; } public function addRole() @@ -65,7 +69,7 @@ final class GoalAggregator implements AggregatorInterface $g = $this->goalRepository->find($value); - return $g->getTitle()['fr']; + return $this->translatableStringHelper->localize($g->getTitle()); }; } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php index 476b6f840..424010138 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php @@ -33,8 +33,8 @@ final class ResultAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb->join('acpw.results', 'r'); - $qb->addSelect('r.id as result_aggregator'); + $qb->join('acpw.results', 'res'); + $qb->addSelect('res.id as result_aggregator'); $groupBy = $qb->getDQLPart('groupBy'); @@ -65,7 +65,7 @@ final class ResultAggregator implements AggregatorInterface $g = $this->resultRepository->find($value); - return $g->getTitle()['fr']; + return $this->translatableStringHelper->localize($g->getTitle()); }; } From a3cae28613e16fd6b6f2020b3cb82a28fca53426 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 9 Aug 2022 16:14:01 +0200 Subject: [PATCH 2/9] residential address at thirdparty filter : not done! --- .../ResidentialAddressAtThirdpartyFilter.php | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php new file mode 100644 index 000000000..83f09bb0d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php @@ -0,0 +1,87 @@ +add('thirdparty_type', EntityType::class, [ + 'class' => ThirdPartyCategory::class, + 'choice_label' => function (ThirdPartyCategory $tpc) { + return $this->translatableStringHelper->localize($tpc->getName()); + }, + 'multiple' => true, + 'expanded' => true + ]); + + $builder->add('date_calc', ChillDateType::class, [ + 'label' => 'Date during which residential address was valid', + 'data' => new DateTime('now'), + ]); + } + + public function alterQuery(QueryBuilder $qb, $data) + { + + //TODO: Query is not finished... not clear what 'catégorie' corresponds with. Cannot get values to appear in table thirdparty_category + $qb->resetDQLPart('from'); + $qb->from('ChillPersonBundle:Person\ResidentialAddress', 'ra'); + + $qb->join('ra.person', 'person'); + $qb->join('person.center', 'center'); + $qb->join('ra.hostThirdparty', 'thirdparty'); + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->andX( + $qb->expr()->isNotNull('ra.hostThirdparty'), + // $qb->expr()->in('thirdparty.categories') + ); + + if ($where instanceof Expr\Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + } + + public function applyOn() + { + return Declarations::PERSON_TYPE; + } + + + public function describeAction($data, $format = 'string') + { + return ['Filtered by person\'s who have a residential address located at a thirdparty of type %thirdparty_type%']; + } + + public function getTitle() + { + return 'Filtered by person\'s who have a residential address located at a thirdparty of type %thirdparty_type%'; + } +} \ No newline at end of file From 6010559936e78806343b1aaabe004a2a7976448f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 9 Aug 2022 16:14:17 +0200 Subject: [PATCH 3/9] translations added --- .../ChillPersonBundle/translations/messages.fr.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 3d30b5c9f..13f92dafd 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -330,14 +330,15 @@ Accompanyied people: Personnes accompagnées ## exports Exports of persons: Exports des personnes -Count people by various parameters.: Compte le nombre de personnes en fonction de différents filtres. -Count people: Nombre de personnes +Count people by various parameters.: Compte le nombre d'usagers en fonction de différents filtres. +Count people: Nombre d'usagers List peoples: Liste des personnes Create a list of people according to various filters.: Crée une liste des personnes selon différents filtres. Fields to include in export: Champs à inclure dans l'export Address valid at this date: Addresse valide à cette date List duplicates: Liste des doublons Create a list of duplicate people: Créer la liste des personnes détectées comme doublons. +Count people with an accompanying course by various parameters.: Nombre d'usagers concernées par un parcours Exports of accompanying courses: Exports des parcours d'accompagnement Count accompanying courses: Nombre de parcours @@ -383,6 +384,9 @@ Minimum age: Âge minimum Maximum age: Âge maximum The minimum age should be less than the maximum age.: L'âge minimum doit être plus bas que l'âge maximum. +Date during which residential address was valid: Date de validité +Filtered by person\'s who have a residential address located at a thirdparty of type %thirparty_type%: Uniquement les usagers qui ont une addresse de résidence chez un tiers de catégorie %thirdparty_type% + Family composition: Composition familiale Family composition at this time: Composition familiale à cette date. @@ -418,6 +422,8 @@ Filter by user job: Filtrer par métier du référent "Filtered by user job: only %job%": "Filtré par métier du référent: uniquement %job%" Group by user job: Grouper par métier du référent +Filter by scope: Filtrer par service + Filter by social issue: Filtrer par problématiques sociales Accepted socialissues: Problématiques sociales "Filtered by socialissues: only %socialissues%": "Filtré par problématique sociale: uniquement %socialissues%" @@ -441,6 +447,10 @@ Evaluation: Évaluation "Filtered by evaluations: only %evals%": "Filtré par évaluation: uniquement %evals%" Group by evaluation: Grouper par évaluation +Group social work actions by action type: Grouper par type d'action +Group social work actions by goal: Grouper par objectif +Group social work actions by result: Grouper par résultat + Filter by activity type: Filtrer par type d'activité Accepted activitytypes: Types d'activités "Filtered by activity types: only %activitytypes%": "Filtré par type d'activité: seulement %activitytypes%" From 5b4b7473c5eea840ed8322d56a09ba90f9f31ed7 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 9 Aug 2022 16:14:41 +0200 Subject: [PATCH 4/9] residential address at user filter done --- .../Filter/PersonFilters/ResidentialAddressAtUserFilter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php index a05e8ef7d..9558c5940 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php @@ -26,7 +26,7 @@ class ResidentialAddressAtUserFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { $qb->resetDQLPart('from'); - $qb->from('ChillPersonBundle:Person:ResidentialAddress', 'ra'); + $qb->from('ChillPersonBundle:Person\ResidentialAddress', 'ra'); $qb->join('ra.person', 'person'); $qb->join('person.center', 'center'); @@ -42,7 +42,6 @@ class ResidentialAddressAtUserFilter implements FilterInterface $qb->add('where', $where); - dump($qb->getQuery()); } public function applyOn() From 97ec921a0a01a9f81b730c139cd2628e4c551e4e Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 9 Aug 2022 16:15:27 +0200 Subject: [PATCH 5/9] small adjustments --- src/Bundle/ChillPersonBundle/Entity/MaritalStatus.php | 2 +- .../PersonAggregators/ProfessionalSitutaionAggregator.php | 8 ++++++-- .../Export/Filter/PersonFilters/EntrustedChildFilter.php | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/MaritalStatus.php b/src/Bundle/ChillPersonBundle/Entity/MaritalStatus.php index 56c9368dc..649830b4a 100644 --- a/src/Bundle/ChillPersonBundle/Entity/MaritalStatus.php +++ b/src/Bundle/ChillPersonBundle/Entity/MaritalStatus.php @@ -31,7 +31,7 @@ class MaritalStatus private ?string $id; /** - * @var string array + * @var array * @ORM\Column(type="json") */ private array $name; diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ProfessionalSitutaionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ProfessionalSitutaionAggregator.php index 0ee31d4fe..476c7ea0a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ProfessionalSitutaionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ProfessionalSitutaionAggregator.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators; use App\Repository\VendeePerson\SituationProfessionelleRepository; use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -22,10 +23,13 @@ use Symfony\Component\Form\FormBuilderInterface; final class ProfessionalSituationAggregator implements AggregatorInterface { private SituationProfessionelleRepository $professionalSituationRepository; + + private TranslatableStringHelper $translatableStringHelper; - public function __construct(SituationProfessionelleRepository $professionalSituationRepository) + public function __construct(SituationProfessionelleRepository $professionalSituationRepository, TranslatableStringHelper $translatableStringHelper) { $this->professionalSituationRepository = $professionalSituationRepository; + $this->translatableStringHelper = $translatableStringHelper; } public function addRole() @@ -70,7 +74,7 @@ final class ProfessionalSituationAggregator implements AggregatorInterface $g = $this->professionalSituationRepository->find($value); - return $g->getName()['fr']; + return $this->translatableStringHelper->localize($g->getName());; }; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/EntrustedChildFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/EntrustedChildFilter.php index ce09901b7..0e85232bf 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/EntrustedChildFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/EntrustedChildFilter.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Export\FilterInterface; use Chill\PersonBundle\Export\Declarations; use DateTime; use Doctrine\ORM\Query\Expr\Andx; +use Symfony\Component\Form\FormBuilderInterface; class EntrustedChildFilter implements FilterInterface { @@ -48,7 +49,7 @@ class EntrustedChildFilter implements FilterInterface return Declarations::PERSON_TYPE; } - public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) + public function buildForm(FormBuilderInterface $builder) { // No form needed } From 2c7a128348ee71246dff5decc45993d91eb9e5cc Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 9 Aug 2022 16:46:29 +0200 Subject: [PATCH 6/9] vendee filters and aggregators moved to root folder --- .../ProfessionalSitutaionAggregator.php | 90 ------------------- .../PersonFilters/EntrustedChildFilter.php | 66 -------------- .../Filter/PersonFilters/NomadicFilter.php | 64 ------------- .../config/services/exports_person.yaml | 21 ----- 4 files changed, 241 deletions(-) delete mode 100644 src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ProfessionalSitutaionAggregator.php delete mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/EntrustedChildFilter.php delete mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/NomadicFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ProfessionalSitutaionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ProfessionalSitutaionAggregator.php deleted file mode 100644 index 476c7ea0a..000000000 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ProfessionalSitutaionAggregator.php +++ /dev/null @@ -1,90 +0,0 @@ -professionalSituationRepository = $professionalSituationRepository; - $this->translatableStringHelper = $translatableStringHelper; - } - - public function addRole() - { - return null; - } - - public function alterQuery(QueryBuilder $qb, $data) - { - $qb->resetDQLPart('from'); - $qb->from('App:VendeePerson', 'vp'); - $qb->join('vp.person', 'person'); - $qb->join('person.center', 'center'); - - $qb->join('vp.situationProfessionelle', 'sp'); - $qb->addSelect('sp.id as professional_situation_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('professional_situation_aggregator'); - } else { - $qb->groupBy('professional_situation_aggregator'); - } - } - - public function applyOn() - { - return Declarations::PERSON_TYPE; - } - - public function buildForm(FormBuilderInterface $builder) - { - } - - public function getLabels($key, array $values, $data) - { - return function ($value): string { - if ('_header' === $value) { - return 'Professional situation'; - } - - $g = $this->professionalSituationRepository->find($value); - - return $this->translatableStringHelper->localize($g->getName());; - }; - } - - public function getQueryKeys($data) - { - return ['professional_situation_aggregator']; - } - - public function getTitle() - { - return 'Group people by their professional situation'; - } -} diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/EntrustedChildFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/EntrustedChildFilter.php deleted file mode 100644 index 0e85232bf..000000000 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/EntrustedChildFilter.php +++ /dev/null @@ -1,66 +0,0 @@ -resetDQLPart('from'); - $qb->from('App:VendeePersonMineur', 'vpm'); - - $qb->join('vpm.person', 'person'); - $qb->join('person.center', 'center'); - - $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->eq('vpm.enfantConfie', 'true'); - - if ($where instanceof Andx) { - $where->add($clause); - } else { - $where = $qb->expr()->andX($clause); - } - - $qb->add('where', $where); - } - - public function applyOn() - { - return Declarations::PERSON_TYPE; - } - - public function buildForm(FormBuilderInterface $builder) - { - // No form needed - } - - public function describeAction($data, $format = 'string') - { - return ['Filtered by entrusted child status']; - } - - public function getTitle() - { - return 'Filter by entrusted child status'; - } -} diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/NomadicFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/NomadicFilter.php deleted file mode 100644 index 33cac6522..000000000 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/NomadicFilter.php +++ /dev/null @@ -1,64 +0,0 @@ -resetDQLPart('from'); - $qb->from('App:VendeePerson', 'vp'); - - $qb->join('vp.person', 'person'); - $qb->join('person.center', 'center'); - - $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->eq('vp.gensDuVoyage', 'true'); - - if ($where instanceof Andx) { - $where->add($clause); - } else { - $where = $qb->expr()->andX($clause); - } - - $qb->add('where', $where); - } - - public function applyOn() - { - return Declarations::PERSON_TYPE; - } - - public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) - { - // No form needed - } - - public function describeAction($data, $format = 'string') - { - return ['Filtered by nomadic status']; - } - - public function getTitle() - { - return 'Filter by nomadic status'; - } -} diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml index c8bd9d76a..d3bb49b6f 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml @@ -68,20 +68,6 @@ services: autoconfigure: true tags: - { name: chill.export_filter, alias: person_residential_address_at_user_filter } - - chill.person.export.filter_entrusted_child: - class: Chill\PersonBundle\Export\Filter\PersonFilters\EntrustedChildFilter - autowire: true - autoconfigure: true - tags: - - { name: chill.export_filter, alias: person_entrusted_child_filter } - - chill.person.export.filter_nomadic: - class: Chill\PersonBundle\Export\Filter\PersonFilters\NomadicFilter - autowire: true - autoconfigure: true - tags: - - { name: chill.export_filter, alias: person_nomadic_filter } ## Aggregators chill.person.export.aggregator_nationality: @@ -118,10 +104,3 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: person_marital_status_aggregator } - - # chill.person.export.aggregator_professional_situation: - # class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\ProfessionalSituationAggregator - # autowire: true - # autoconfigure: true - # tags: - # - { name: chill.export_aggregator, alias: person_professional_situation_aggregator } From 3c451209c7cdf1fda5f2a04683d52c2a524576a8 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 10 Aug 2022 10:35:32 +0200 Subject: [PATCH 7/9] fix nationality aggregator --- .../Repository/CountryRepository.php | 6 ++++++ .../PersonAggregators/NationalityAggregator.php | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Repository/CountryRepository.php b/src/Bundle/ChillMainBundle/Repository/CountryRepository.php index 81bea648d..055f41195 100644 --- a/src/Bundle/ChillMainBundle/Repository/CountryRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/CountryRepository.php @@ -14,6 +14,7 @@ namespace Chill\MainBundle\Repository; use Chill\MainBundle\Entity\Country; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ObjectRepository; final class CountryRepository implements ObjectRepository @@ -25,6 +26,11 @@ final class CountryRepository implements ObjectRepository $this->repository = $entityManager->getRepository(Country::class); } + public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder + { + return $this->repository->createQueryBuilder($alias, $indexBy); + } + public function find($id, $lockMode = null, $lockVersion = null): ?Country { return $this->repository->find($id, $lockMode, $lockVersion); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/NationalityAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/NationalityAggregator.php index b8c9ba166..b4c2bc31a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/NationalityAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/NationalityAggregator.php @@ -124,17 +124,19 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV ->getQuery() ->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR); + // initialize array and add blank key for null values $labels = [ '' => $this->translator->trans('without data'), '_header' => $this->translator->trans('Nationality'), ]; + foreach ($countries as $row) { $labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']); } } - + if ('continent' === $data['group_by_level']) { $labels = [ 'EU' => $this->translator->trans('Europe'), @@ -149,9 +151,16 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV ]; } - return static function (string $value) use ($labels): string { + return function ($value) use ($labels): string { + // if ('_header' === $value) { + // return 'Marital status'; + // } return $labels[$value]; }; + // return static function (string $value) use ($labels): string { + // dump($labels[$value]); + // return $labels[$value]; + // }; } public function getQueryKeys($data) From 6eddb420cc41718b88d6a41c331c933ddb34386d Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 10 Aug 2022 10:35:32 +0200 Subject: [PATCH 8/9] fix nationality aggregator --- .../ChillMainBundle/Repository/CountryRepository.php | 6 ++++++ .../Aggregator/PersonAggregators/NationalityAggregator.php | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Repository/CountryRepository.php b/src/Bundle/ChillMainBundle/Repository/CountryRepository.php index 81bea648d..055f41195 100644 --- a/src/Bundle/ChillMainBundle/Repository/CountryRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/CountryRepository.php @@ -14,6 +14,7 @@ namespace Chill\MainBundle\Repository; use Chill\MainBundle\Entity\Country; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ObjectRepository; final class CountryRepository implements ObjectRepository @@ -25,6 +26,11 @@ final class CountryRepository implements ObjectRepository $this->repository = $entityManager->getRepository(Country::class); } + public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder + { + return $this->repository->createQueryBuilder($alias, $indexBy); + } + public function find($id, $lockMode = null, $lockVersion = null): ?Country { return $this->repository->find($id, $lockMode, $lockVersion); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/NationalityAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/NationalityAggregator.php index b8c9ba166..8c3c0e9a7 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/NationalityAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/NationalityAggregator.php @@ -124,17 +124,19 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV ->getQuery() ->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR); + // initialize array and add blank key for null values $labels = [ '' => $this->translator->trans('without data'), '_header' => $this->translator->trans('Nationality'), ]; + foreach ($countries as $row) { $labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']); } } - + if ('continent' === $data['group_by_level']) { $labels = [ 'EU' => $this->translator->trans('Europe'), @@ -149,9 +151,10 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV ]; } - return static function (string $value) use ($labels): string { + return function ($value) use ($labels): string { return $labels[$value]; }; + } public function getQueryKeys($data) From 0c2c364eb668936b25eb9477201e713208ce3e07 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 10 Aug 2022 13:58:51 +0200 Subject: [PATCH 9/9] trying to get dynamic form to work --- .../SocialWorkTypeFilter.php | 159 ++++-------------- 1 file changed, 32 insertions(+), 127 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php index bf28fb695..b5b8fbfd1 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php @@ -3,6 +3,7 @@ namespace Chill\PersonBundle\Export\Filter\SocialWorkFilters; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\SocialWork\Goal; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\Query\Expr\Andx; @@ -12,117 +13,27 @@ use Symfony\Component\Form\FormBuilderInterface; use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Chill\PersonBundle\Templating\Entity\SocialActionRender; use Doctrine\ORM\EntityRepository; +use Symfony\Component\Form\Event\PostSetDataEvent; +use Symfony\Component\Form\Event\PostSubmitEvent; use Symfony\Component\Form\Event\PreSetDataEvent; +use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; +use Symfony\Component\Form\FormInterface; class SocialWorkTypeFilter implements FilterInterface { private SocialActionRender $socialActionRender; - public function __construct(SocialActionRender $socialActionRender) + private TranslatableStringHelper $translatableStringHelper; + + public function __construct(SocialActionRender $socialActionRender, TranslatableStringHelper $translatableStringHelper) { $this->socialActionRender = $socialActionRender; + $this->translatableStringHelper = $translatableStringHelper; } public function buildForm(FormBuilderInterface $builder) { - /** - * EXAMPLE CODE TO INSPIRE - */ - // parent::buildForm($builder, $options); - // //other fields - - // $builder->add('country', 'entity', array( - // 'class' => 'Orfos\CoreBundle\Entity\Country', - // 'property' => $locale . 'name', - // 'label' => 'register.country.label', - // 'query_builder' => function(EntityRepository $er) { - // return $er->createQueryBuilder('c') - // ->select('c', 't') - // ->join('c.translations', 't'); - // }, - // )); - - // $factory = $builder->getFormFactory(); - // $refreshRegion = function ($form, $country) use ($factory, $locale) { - // $form->add($factory->createNamed('entity', 'region', null, array( - // 'class' => 'Orfos\CoreBundle\Entity\Region', - // 'property' => $locale . 'name', - // 'label' => 'register.region.label', - // 'query_builder' => function (EntityRepository $repository) use ($country) { - // $qb = $repository->createQueryBuilder('region') - // ->select('region', 'translation') - // ->innerJoin('region.country', 'country') - // ->join('region.translations', 'translation'); - - // if ($country instanceof Country) { - // $qb = $qb->where('region.country = :country') - // ->setParameter('country', $country); - // } elseif (is_numeric($country)) { - // $qb = $qb->where('country.id = :country_id') - // ->setParameter('country_id', $country); - // } else { - // $qb = $qb->where('country.id = 1'); - // } - - // return $qb; - // } - // ))); - // }; - // $factory = $builder->getFormFactory(); - // $refreshCity = function($form, $region) use ($factory, $locale) { - // $form->add($factory->createNamed('entity', 'city', null, array( - // 'class' => 'Orfos\CoreBundle\Entity\City', - // 'property' => $locale . 'name', - // 'label' => 'register.city.label', - // 'query_builder' => function (EntityRepository $repository) use ($region) { - // $qb = $repository->createQueryBuilder('city') - // ->select('city', 'translation') - // ->innerJoin('city.region', 'region') - // ->innerJoin('city.translations', 'translation'); - - // if ($region instanceof Region) { - // $qb = $qb->where('city.region = :region') - // ->setParameter('region', $region); - // } elseif (is_numeric($region)) { - // $qb = $qb->where('region.id = :region_id') - // ->setParameter('region_id', $region); - // } else { - // $qb = $qb->where('region.id = 1'); - // } - - // return $qb; - // } - // ))); - // }; - - // $builder->addEventListener(FormEvents::PRE_SET_DATA, function (DataEvent $event) use ($refreshRegion, $refreshCity) { - // $form = $event->getForm(); - // $data = $event->getData(); - - // if ($data == null){ - // $refreshRegion($form, null); - // $refreshCity($form, null); - // } - - // if ($data instanceof Country) { - // $refreshRegion($form, $data->getCountry()->getRegions()); - // $refreshCity($form, $data->getRegion()->getCities()); - // } - // }); - - // $builder->addEventListener(FormEvents::PRE_BIND, function (DataEvent $event) use ($refreshRegion, $refreshCity) { - // $form = $event->getForm(); - // $data = $event->getData(); - - // if (array_key_exists('country', $data)) { - // $refreshRegion($form, $data['country']); - // } - // if (array_key_exists('region', $data)) { - // $refreshCity($form, $data['region']); - // } - // }); - $builder->add('actionType', EntityType::class, [ 'class' => SocialAction::class, @@ -133,45 +44,39 @@ class SocialWorkTypeFilter implements FilterInterface 'expanded' => true ]); - $refreshGoals = function ($form, $actionType) { + $refreshGoals = function (FormInterface $form, SocialAction $actionType = null) { + + $goals = null === $actionType ? [] : $actionType->getGoals(); + $form->add('goal', EntityType::class, [ 'class' => Goal::class, + 'placeholder' => '', + 'choices' => $goals, 'choice_label' => function (Goal $g) { - return $g->getTitle(); + return $this->translatableStringHelper->localize($g->getTitle()); }, - 'query_builder' => function (EntityRepository $repository) use ($actionType) { - $qb = $repository->createQueryBuilder('g') - ->select('g') - ->join('g.socialActions', 'socialActions'); - - if ($actionType instanceof SocialAction) { - $qb = $qb->where( - $qb->expr()->andX( - $qb->expr()->in('g', ':socialActions') - )) - ->setParameter('country', $actionType); - } - - dump($qb->getQuery()->getResult()); - - return $qb; - } ]); - }; + }; - $builder->addEventListener(FormEvents::PRE_SET_DATA, function (PreSetDataEvent $event) use ($refreshGoals) { + $builder->addEventListener(FormEvents::POST_SUBMIT, function (PostSubmitEvent $event) use ($refreshGoals) { + dump($event); $form = $event->getForm(); $data = $event->getData(); - if ($data == null){ - $refreshGoals($form, null); - } - - if ($data instanceof SocialAction) { - $refreshGoals($form, $data->getGoals()); - // $refreshCity($form, $data->getRegion()->getCities()); - } + $refreshGoals($form, $data); + }); + + $builder->get('actionType')->addEventListener( + FormEvents::POST_SUBMIT, + function (FormEvent $event) use ($refreshGoals) { + $actionType = $event->getForm()->getData(); + dump('after submit listener'); + dump($actionType); + + $refreshGoals($event->getForm()->getParent(), $actionType); + } + ); } public function getTitle(): string