From 51168ac3c4a397d6de6064be002ccaadae984456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 17 Jun 2025 17:45:26 +0200 Subject: [PATCH] In SocialActionFilter, mention the social issue and if a social action is deactivated All the social action are shown, even the deactivated. So, we append the fact the the social action is also deactivated. We added option in SocialActionRender to achieve this. --- .../translations/messages.fr.yml | 2 +- .../SocialActionFilter.php | 5 +++ .../Form/Type/PickSocialActionType.php | 16 +++++++-- .../Templating/Entity/SocialActionRender.php | 33 ++++++++++++++++++- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index c0394df5d..68878c45c 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -15,7 +15,7 @@ Login to %installation_name%: Connexion à %installation_name% Enabled: Activé enabled: activé disabled: désactivé -Disabled: Désacdtivé +Disabled: Désactivé Id: identifiant Homepage: Accueil Welcome: Bienvenue diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php index 1c108ae03..e3ce3928c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php @@ -89,11 +89,16 @@ final readonly class SocialActionFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder): void { + $actions = $this->socialActionRepository->findAllOrdered(); + $builder ->add('accepted_socialactions', PickSocialActionType::class, [ 'multiple' => true, 'label' => 'export.filter.course.by_social_action.Accepted socialactions', 'help' => 'export.filter.course.by_social_action.accepted socialations help', + 'show_social_issue_parenthesis' => true, + 'show_deactivated' => true, + 'choices' => $actions, ]) ->add('start_date_after', PickRollingDateType::class, [ 'label' => 'export.filter.course.by_social_action.start date after', diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickSocialActionType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickSocialActionType.php index 19258f23d..1e6f2ba1a 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/PickSocialActionType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickSocialActionType.php @@ -16,6 +16,7 @@ use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository; use Chill\PersonBundle\Templating\Entity\SocialActionRender; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; class PickSocialActionType extends AbstractType @@ -28,14 +29,25 @@ class PickSocialActionType extends AbstractType ->setDefaults([ 'class' => SocialAction::class, 'choices' => $this->actionRepository->findAllActive(), - 'choice_label' => fn (SocialAction $sa) => $this->actionRender->renderString($sa, []), 'placeholder' => 'Pick a social action', 'required' => false, 'attr' => ['class' => 'select2'], 'label' => 'Social actions', 'multiple' => false, + 'show_social_issue_parenthesis' => false, + 'show_deactivated' => false, ]) - ->setAllowedTypes('multiple', ['bool']); + ->setNormalizer('choice_label', function (Options $options, $value) { + return fn (SocialAction $sa) => $this->actionRender->renderString( + $sa, + [ + SocialActionRender::SHOW_SOCIAL_ISSUE => $options['show_social_issue_parenthesis'], + SocialActionRender::SHOW_DEACTIVATED => $options['show_deactivated'], + ] + ); + }) + ->setAllowedTypes('multiple', ['bool']) + ->setAllowedTypes('show_social_issue_parenthesis', ['bool']); } public function getParent(): string diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php index 657ed0f53..13e93cf22 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php @@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Templating\Entity; use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\SocialWork\SocialAction; +use Symfony\Component\Clock\ClockInterface; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -28,6 +29,8 @@ class SocialActionRender implements ChillEntityRenderInterface self::NO_BADGE => false, self::SHOW_AND_CHILDREN => false, self::AND_CHILDREN_MENTION => 'social_action.and children', + self::SHOW_SOCIAL_ISSUE => false, + self::SHOW_DEACTIVATED => false, ]; /** @@ -43,7 +46,27 @@ class SocialActionRender implements ChillEntityRenderInterface */ final public const SHOW_AND_CHILDREN = 'show_and_children'; - public function __construct(private readonly TranslatableStringHelper $translatableStringHelper, private readonly \Twig\Environment $engine, private readonly TranslatorInterface $translator) {} + /** + * Append the related social issue next to the social action name, in parenthesis. + * + * Currently only in string rendering. + */ + final public const SHOW_SOCIAL_ISSUE = 'show_social_issue'; + + /** + * Append a mention "deactivated" next to the social action name, in parenthesis, if the social action is deactivated. + * + * Currently only in string rendering. + */ + final public const SHOW_DEACTIVATED = 'show_deactivated'; + + public function __construct( + private readonly TranslatableStringHelper $translatableStringHelper, + private readonly \Twig\Environment $engine, + private readonly TranslatorInterface $translator, + private readonly SocialIssueRender $socialIssueRender, + private readonly ClockInterface $clock, + ) {} public function renderBox($socialAction, array $options): string { @@ -79,6 +102,14 @@ class SocialActionRender implements ChillEntityRenderInterface $title .= ' ('.$this->translator->trans($options[self::AND_CHILDREN_MENTION]).')'; } + if ($options[self::SHOW_SOCIAL_ISSUE]) { + $title .= ' ('.$this->socialIssueRender->renderString($socialAction->getIssue(), []).')'; + } + + if ($options[self::SHOW_DEACTIVATED] && $socialAction->isDesactivated(\DateTime::createFromImmutable($this->clock->now()))) { + $title .= ' ('.$this->translator->trans('Disabled').')'; + } + return $title; }