mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-22 10:14:24 +00:00
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:
parent
12ee091d09
commit
51168ac3c4
@ -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
|
||||
|
@ -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',
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user