From 50609065911ac8753e5d7051fd7680d9f1d6bd57 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 17 Aug 2022 16:03:58 +0200 Subject: [PATCH] more attempts to make dynamic form work --- .../SocialWorkTypeFilter.php | 32 +++++++++++-------- .../services/exports_social_actions.yaml | 22 ++++++------- .../translations/messages.fr.yml | 2 ++ 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php index b5b8fbfd1..4eec8dd69 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php @@ -6,9 +6,11 @@ use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\SocialWork\Goal; use Chill\PersonBundle\Export\Declarations; +use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Chill\PersonBundle\Templating\Entity\SocialActionRender; @@ -26,17 +28,26 @@ class SocialWorkTypeFilter implements FilterInterface private TranslatableStringHelper $translatableStringHelper; - public function __construct(SocialActionRender $socialActionRender, TranslatableStringHelper $translatableStringHelper) + private SocialActionRepository $socialActionRepository; + + public function __construct + ( + SocialActionRender $socialActionRender, + TranslatableStringHelper $translatableStringHelper, + SocialActionRepository $socialActionRepository + ) { $this->socialActionRender = $socialActionRender; $this->translatableStringHelper = $translatableStringHelper; + $this->socialActionRepository = $socialActionRepository; } public function buildForm(FormBuilderInterface $builder) { + $socialActions = $this->socialActionRepository->findAll(); - $builder->add('actionType', EntityType::class, [ - 'class' => SocialAction::class, + $builder->add('actionType', ChoiceType::class, [ + 'choices' => $socialActions, 'choice_label' => function (SocialAction $sa) { return $this->socialActionRender->renderString($sa, []); }, @@ -48,8 +59,7 @@ class SocialWorkTypeFilter implements FilterInterface $goals = null === $actionType ? [] : $actionType->getGoals(); - $form->add('goal', EntityType::class, [ - 'class' => Goal::class, + $form->add('goal', ChoiceType::class, [ 'placeholder' => '', 'choices' => $goals, 'choice_label' => function (Goal $g) { @@ -58,22 +68,18 @@ class SocialWorkTypeFilter implements FilterInterface ]); }; - $builder->addEventListener(FormEvents::POST_SUBMIT, function (PostSubmitEvent $event) use ($refreshGoals) { - dump($event); - $form = $event->getForm(); + $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($refreshGoals) { $data = $event->getData(); + dump($data); - $refreshGoals($form, $data); - + $refreshGoals($event->getForm(), $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); } ); @@ -129,4 +135,4 @@ class SocialWorkTypeFilter implements FilterInterface { return Declarations::SOCIAL_WORK_ACTION_TYPE; } -} \ No newline at end of file +} diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml index ef86732ff..d5f7376db 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml @@ -1,4 +1,4 @@ -services: +services: chill.person.export.count_social_work_actions: class: Chill\PersonBundle\Export\Export\CountSocialWorkActions @@ -6,15 +6,15 @@ services: autoconfigure: true tags: - { name: chill.export, alias: count_social_work_actions } - + ## FILTERS - # chill.person.export.filter_social_work_type: - # class: Chill\PersonBundle\Export\Filter\SocialWorkFilters\SocialWorkTypeFilter - # autowire: true - # autoconfigure: true - # tags: - # - { name: chill.export_filter, alias: social_work_type_filter } + chill.person.export.filter_social_work_type: + class: Chill\PersonBundle\Export\Filter\SocialWorkFilters\SocialWorkTypeFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: social_work_type_filter } chill.person.export.filter_scope: class: Chill\PersonBundle\Export\Filter\SocialWorkFilters\ScopeFilter @@ -36,7 +36,7 @@ services: autoconfigure: true tags: - { name: chill.export_filter, alias: social_work_actions_treatingagent_filter } - + ## AGGREGATORS chill.person.export.aggregator_action_type: class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ActionTypeAggregator @@ -65,14 +65,14 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: social_work_actions_treatingagent_aggregator } - + chill.person.export.aggregator_goal: class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\GoalAggregator autowire: true autoconfigure: true tags: - { name: chill.export_aggregator, alias: social_work_actions_goal_aggregator } - + chill.person.export.aggregator_result: class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ResultAggregator autowire: true diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 58ed3204e..c18e6ce29 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -352,6 +352,7 @@ Exports of social work actions: Exports des actions d'accompangement Count social work actions: Nombre d'actions d'accompagnement Count social work actions by various parameters: Compte le nombre d'actions d'accompagnement en fonction de différents filtres. + Exports of evaluations: Exports des évaluations Count evaluations: Nombre d'évaluations Count evaluation by various parameters.: Compte le nombre d'évaluations selon différents filtres. @@ -448,6 +449,7 @@ Filter by socialaction: Filtrer les parcours par action d'accompagnement Accepted socialactions: Actions d'accompagnement "Filtered by socialactions: only %socialactions%": "Filtré par action d'accompagnement: uniquement %socialactions%" Group by social action: Grouper les parcours par action d'accompagnement +Filter by type of action, objectives and results: "Filtrer par type d'action, objectif et résultat" Filter by evaluation: Filtrer les parcours par évaluation Accepted evaluations: Évaluations