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.
This commit is contained in:
Julien Fastré 2025-06-17 17:45:26 +02:00
parent 12ee091d09
commit 51168ac3c4
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
4 changed files with 52 additions and 4 deletions

View File

@ -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

View File

@ -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',

View File

@ -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

View File

@ -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;
}