diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php index f15d88bb0..a7d6e5e3a 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialActionFilter.php @@ -13,7 +13,8 @@ namespace Chill\ActivityBundle\Export\Filter\ACPFilters; use Chill\ActivityBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; -use Chill\PersonBundle\Form\Type\Select2SocialActionType; +use Chill\PersonBundle\Entity\SocialWork\SocialAction; +use Chill\PersonBundle\Form\Type\PickSocialActionType; use Chill\PersonBundle\Templating\Entity\SocialActionRender; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -41,8 +42,10 @@ class BySocialActionFilter implements FilterInterface $clause = $qb->expr()->in('actsocialaction.id', ':socialactions'); - $qb ->andWhere($clause) - ->setParameter('socialactions', $data['accepted_socialactions']); + $qb->andWhere($clause) + ->setParameter('socialactions', + SocialAction::getDescendantsWithThisForActions($data['accepted_socialactions']) + ); } public function applyOn(): string @@ -52,7 +55,7 @@ class BySocialActionFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('accepted_socialactions', Select2SocialActionType::class, [ + $builder->add('accepted_socialactions', PickSocialActionType::class, [ 'multiple' => true ]); } @@ -61,8 +64,10 @@ class BySocialActionFilter implements FilterInterface { $actions = []; - foreach ($data['accepted_socialactions'] as $sa) { - $actions[] = $this->actionRender->renderString($sa, []); + foreach ($data['accepted_socialactions'] as $action) { + $actions[] = $this->actionRender->renderString($action, [ + 'show_and_children' => true, + ]); } return ['Filtered activity by linked socialaction: only %actions%', [ diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php index b9d1856c8..94189169d 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/BySocialIssueFilter.php @@ -13,7 +13,8 @@ namespace Chill\ActivityBundle\Export\Filter\ACPFilters; use Chill\ActivityBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; -use Chill\PersonBundle\Form\Type\Select2SocialIssueType; +use Chill\PersonBundle\Entity\SocialWork\SocialIssue; +use Chill\PersonBundle\Form\Type\PickSocialIssueType; use Chill\PersonBundle\Templating\Entity\SocialIssueRender; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -41,8 +42,10 @@ class BySocialIssueFilter implements FilterInterface $clause = $qb->expr()->in('actsocialissue.id', ':socialissues'); - $qb ->andWhere($clause) - ->setParameter('socialissues', $data['accepted_socialissues']); + $qb->andWhere($clause) + ->setParameter('socialissues', + SocialIssue::getDescendantsWithThisForIssues($data['accepted_socialissues']) + ); } public function applyOn(): string @@ -52,7 +55,7 @@ class BySocialIssueFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('accepted_socialissues', Select2SocialIssueType::class, [ + $builder->add('accepted_socialissues', PickSocialIssueType::class, [ 'multiple' => true ]); } @@ -61,8 +64,10 @@ class BySocialIssueFilter implements FilterInterface { $issues = []; - foreach ($data['accepted_socialissues'] as $si) { - $issues[] = $this->issueRender->renderString($si, []); + foreach ($data['accepted_socialissues'] as $issue) { + $issues[] = $this->issueRender->renderString($issue, [ + 'show_and_children' => true, + ]); } return ['Filtered activity by linked socialissue: only %issues%', [ diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/LocationTypeFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/LocationTypeFilter.php index 023882cf9..2c9244022 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/LocationTypeFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/LocationTypeFilter.php @@ -13,7 +13,7 @@ namespace Chill\ActivityBundle\Export\Filter\ACPFilters; use Chill\ActivityBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\Select2LocationTypeType; +use Chill\MainBundle\Form\Type\PickLocationTypeType; use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; @@ -60,7 +60,7 @@ class LocationTypeFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('accepted_locationtype', Select2LocationTypeType::class, [ + $builder->add('accepted_locationtype', PickLocationTypeType::class, [ 'multiple' => true, //'label' => false, ]); diff --git a/src/Bundle/ChillMainBundle/Form/Type/Select2LocationTypeType.php b/src/Bundle/ChillMainBundle/Form/Type/PickLocationTypeType.php similarity index 96% rename from src/Bundle/ChillMainBundle/Form/Type/Select2LocationTypeType.php rename to src/Bundle/ChillMainBundle/Form/Type/PickLocationTypeType.php index 33121f8bb..6774e0941 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Select2LocationTypeType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PickLocationTypeType.php @@ -17,7 +17,7 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\OptionsResolver\OptionsResolver; -class Select2LocationTypeType extends AbstractType +class PickLocationTypeType extends AbstractType { private TranslatableStringHelper $translatableStringHelper; diff --git a/src/Bundle/ChillMainBundle/Form/Type/Select2UserLocationType.php b/src/Bundle/ChillMainBundle/Form/Type/PickUserLocationType.php similarity index 97% rename from src/Bundle/ChillMainBundle/Form/Type/Select2UserLocationType.php rename to src/Bundle/ChillMainBundle/Form/Type/PickUserLocationType.php index 3c1e51e68..792daa39e 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Select2UserLocationType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PickUserLocationType.php @@ -18,7 +18,7 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\OptionsResolver\OptionsResolver; -class Select2UserLocationType extends AbstractType +class PickUserLocationType extends AbstractType { private LocationRepository $locationRepository; diff --git a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php index f1ef83a9f..657ba8942 100644 --- a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php +++ b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php @@ -11,7 +11,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Form; -use Chill\MainBundle\Form\Type\Select2UserLocationType; +use Chill\MainBundle\Form\Type\PickUserLocationType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; @@ -20,7 +20,7 @@ class UserCurrentLocationType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('currentLocation', Select2UserLocationType::class); + $builder->add('currentLocation', PickUserLocationType::class); } } diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index 34f5d1802..4408a7223 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -130,14 +130,6 @@ services: autowire: true autoconfigure: true - Chill\MainBundle\Form\Type\Select2UserLocationType: - autowire: true - autoconfigure: true - - Chill\MainBundle\Form\Type\Select2LocationTypeType: - autowire: true - autoconfigure: true - Chill\MainBundle\Form\Type\LocationFormType: ~ Chill\MainBundle\Form\WorkflowStepType: ~ diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index bc81bc180..ea5df8fe0 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -227,6 +227,23 @@ class SocialAction return $descendants; } + /** + * @param Collection|SocialAction[] $socialActions + * @return Collection + */ + public static function getDescendantsWithThisForActions($socialActions): Collection + { + $unique = []; + + foreach ($socialActions as $action) { + foreach ($action->getDescendantsWithThis() as $child) { + $unique[spl_object_hash($child)] = $child; + } + } + + return new ArrayCollection(array_values($unique)); + } + public function getEvaluations(): Collection { return $this->evaluations; @@ -278,6 +295,11 @@ class SocialAction return $this->getParent() instanceof self; } + public function hasChildren(): bool + { + return 0 < $this->getChildren()->count(); + } + /** * Recursive method which return true if the current $action * is a descendant of the $action given in parameter. diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php index 06f05c91f..d36642977 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php @@ -215,6 +215,23 @@ class SocialIssue return $descendants; } + /** + * @param Collection|SocialIssue[] $socialIssues + * @return Collection + */ + public static function getDescendantsWithThisForIssues(Collection $socialIssues): Collection + { + $unique = []; + + foreach ($socialIssues as $issue) { + foreach ($issue->getDescendantsWithThis() as $child) { + $unique[spl_object_hash($child)] = $child; + } + } + + return new ArrayCollection(array_values($unique)); + } + public function getId(): ?int { return $this->id; @@ -267,6 +284,11 @@ class SocialIssue return null !== $this->parent; } + public function hasChildren(): bool + { + return 0 < $this->getChildren()->count(); + } + /** * Recursive method which return true if the current $issue is a descendant * of the $issue given in parameter. diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilter.php index d289220af..19f1a6090 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilter.php @@ -12,7 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\Select2UserLocationType; +use Chill\MainBundle\Form\Type\PickUserLocationType; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\QueryBuilder; @@ -48,7 +48,7 @@ class AdministrativeLocationFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('accepted_locations', Select2UserLocationType::class, [ + $builder->add('accepted_locations', PickUserLocationType::class, [ 'label' => 'Accepted locations', 'label_attr' => [ //'class' => 'd-none' diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php index 138583ef2..a1834aa0e 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php @@ -15,7 +15,7 @@ use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Chill\PersonBundle\Export\Declarations; -use Chill\PersonBundle\Form\Type\Select2SocialActionType; +use Chill\PersonBundle\Form\Type\PickSocialActionType; use Chill\PersonBundle\Templating\Entity\SocialActionRender; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -23,10 +23,10 @@ use function in_array; class SocialActionFilter implements FilterInterface { - private SocialActionRender $actionRender; - private TranslatableStringHelper $translatableStringHelper; + private SocialActionRender $actionRender; + public function __construct( TranslatableStringHelper $translatableStringHelper, SocialActionRender $actionRender @@ -52,9 +52,9 @@ class SocialActionFilter implements FilterInterface $clause = $qb->expr()->in('acpwsocialaction.id', ':socialactions'); - $qb ->andWhere($clause) + $qb->andWhere($clause) ->setParameter('socialactions', - $this->addDescendantsActions($data['accepted_socialactions']) + SocialAction::getDescendantsWithThisForActions($data['accepted_socialactions'])->toArray() ); } @@ -65,7 +65,7 @@ class SocialActionFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('accepted_socialactions', Select2SocialActionType::class, [ + $builder->add('accepted_socialactions', PickSocialActionType::class, [ 'multiple' => true, ]); } @@ -77,7 +77,9 @@ class SocialActionFilter implements FilterInterface $socialactions = $data['accepted_socialactions']; foreach ($socialactions as $action) { - $actions[] = $this->renderAction($action); + $actions[] = $this->actionRender->renderString($action, [ + 'show_and_children' => true, + ]); } return ['Filtered by socialactions: only %socialactions%', [ @@ -89,45 +91,4 @@ class SocialActionFilter implements FilterInterface { return 'Filter by socialaction'; } - - private function addDescendantsActions($accepted_socialactions): array - { - $array = []; - - foreach ($accepted_socialactions as $action) { - /** @var SocialAction $action */ - $array[] = $action; - if (!$action->hasParent()) { - $array = array_merge($array, $action->getDescendants()->toArray()); - } - } - - return $this->removeDuplicate($array); - } - - private function removeDuplicate(array $array): array - { - $ids = array_map(static function ($item) { - return $item->getId(); - }, $array); - - $unique_ids = array_unique($ids); - - return array_values( - array_intersect_key($array, $unique_ids) - ); - } - - private function renderAction(SocialAction $action): string - { - $render_str = $this->actionRender->renderString($action, []); - - if (!$action->hasParent()) { - if (count($action->getDescendants()) > 0) { - return $render_str . " (et dérivés)"; - } - } - - return $render_str; - } } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialIssueFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialIssueFilter.php index c72c78aa5..08ab7fca2 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialIssueFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialIssueFilter.php @@ -15,7 +15,7 @@ use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\PersonBundle\Export\Declarations; -use Chill\PersonBundle\Form\Type\Select2SocialIssueType; +use Chill\PersonBundle\Form\Type\PickSocialIssueType; use Chill\PersonBundle\Templating\Entity\SocialIssueRender; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -56,9 +56,9 @@ class SocialIssueFilter implements FilterInterface $clause = $qb->expr()->in('acpsocialissue.id', ':socialissues'); - $qb ->andWhere($clause) + $qb->andWhere($clause) ->setParameter('socialissues', - $this->addDescendantsIssues($data['accepted_socialissues']) + SocialIssue::getDescendantsWithThisForIssues($data['accepted_socialissues']) ); } @@ -69,7 +69,7 @@ class SocialIssueFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('accepted_socialissues', Select2SocialIssueType::class, [ + $builder->add('accepted_socialissues', PickSocialIssueType::class, [ 'multiple' => true, ]); } @@ -80,14 +80,10 @@ class SocialIssueFilter implements FilterInterface $socialissues = $data['accepted_socialissues']; - foreach ($socialissues as $si) { - /** @var SocialIssue $si */ - if (null === $si) { - $issues[] = $this->translator->trans('Not given'); - } else { - $issues[] = $this->renderIssue($si); - - } + foreach ($socialissues as $issue) { + $issues[] = $this->socialIssueRender->renderString($issue, [ + 'show_and_children' => true, + ]); } return [ @@ -100,45 +96,4 @@ class SocialIssueFilter implements FilterInterface { return 'Filter by social issue'; } - - private function addDescendantsIssues($accepted_socialissues): array - { - $array = []; - - foreach ($accepted_socialissues as $si) { - /** @var SocialIssue $si */ - $array[] = $si; - if (!$si->hasParent()) { - $array = array_merge($array, $si->getDescendants()->toArray()); - } - } - - return $this->removeDuplicate($array); - } - - private function removeDuplicate(array $array): array - { - $ids = array_map(static function ($item) { - return $item->getId(); - }, $array); - - $unique_ids = array_unique($ids); - - return array_values( - array_intersect_key($array, $unique_ids) - ); - } - - private function renderIssue(SocialIssue $si): string - { - $render_str = $this->socialIssueRender->renderString($si, []); - - if (!$si->hasParent()) { - if (count($si->getDescendants()) > 0) { - return $render_str . " (et dérivés)"; - } - } - - return $render_str; - } } diff --git a/src/Bundle/ChillPersonBundle/Form/Type/Select2SocialActionType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickSocialActionType.php similarity index 92% rename from src/Bundle/ChillPersonBundle/Form/Type/Select2SocialActionType.php rename to src/Bundle/ChillPersonBundle/Form/Type/PickSocialActionType.php index ab22f2972..7c0da43b1 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/Select2SocialActionType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickSocialActionType.php @@ -18,7 +18,7 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\OptionsResolver\OptionsResolver; -class Select2SocialActionType extends AbstractType +class PickSocialActionType extends AbstractType { private SocialActionRender $actionRender; @@ -37,7 +37,7 @@ class Select2SocialActionType extends AbstractType $resolver ->setDefaults([ 'class' => SocialAction::class, - 'choices' => $this->actionRepository->findActionsNotDesactivated(), + 'choices' => $this->actionRepository->findAllActive(), 'choice_label' => function (SocialAction $sa) { return $this->actionRender->renderString($sa, []); }, diff --git a/src/Bundle/ChillPersonBundle/Form/Type/Select2SocialIssueType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickSocialIssueType.php similarity index 92% rename from src/Bundle/ChillPersonBundle/Form/Type/Select2SocialIssueType.php rename to src/Bundle/ChillPersonBundle/Form/Type/PickSocialIssueType.php index 615c2830d..e79c17191 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/Select2SocialIssueType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickSocialIssueType.php @@ -18,7 +18,7 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\OptionsResolver\OptionsResolver; -class Select2SocialIssueType extends AbstractType +class PickSocialIssueType extends AbstractType { private SocialIssueRender $issueRender; @@ -37,7 +37,7 @@ class Select2SocialIssueType extends AbstractType $resolver ->setDefaults([ 'class' => SocialIssue::class, - 'choices' => $this->issueRepository->findIssuesNotDesactivated(), + 'choices' => $this->issueRepository->findAllActive(), 'choice_label' => function (SocialIssue $si) { return $this->issueRender->renderString($si, []); }, diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php index 3b8715d7e..86e8e41a8 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php @@ -68,7 +68,10 @@ final class SocialActionRepository implements ObjectRepository return SocialAction::class; } - public function findActionsNotDesactivated(): array + /** + * @return array|SocialAction[] + */ + public function findAllActive(): array { return $this->buildQueryWithDesactivatedDateCriteria()->getQuery()->getResult(); } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php index 0c18cd970..21831b432 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php @@ -63,7 +63,10 @@ final class SocialIssueRepository implements ObjectRepository return SocialIssue::class; } - public function findIssuesNotDesactivated(): array + /** + * @return array|SocialIssue[] + */ + public function findAllActive(): array { return $this->buildQueryWithDesactivatedDateCriteria()->getQuery()->getResult(); } diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php index f2ee13fc1..8f1bfaccb 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialActionRender.php @@ -15,7 +15,7 @@ use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Symfony\Component\Templating\EngineInterface; - +use Symfony\Contracts\Translation\TranslatorInterface; use function array_merge; use function array_reverse; use function implode; @@ -25,6 +25,8 @@ class SocialActionRender implements ChillEntityRenderInterface public const DEFAULT_ARGS = [ self::SEPARATOR_KEY => ' > ', self::NO_BADGE => false, + self::SHOW_AND_CHILDREN => false, + self::AND_CHILDREN_MENTION => 'social_action.and children', ]; /** @@ -34,14 +36,28 @@ class SocialActionRender implements ChillEntityRenderInterface public const SEPARATOR_KEY = 'default.separator'; + /** + * Show a mention "and children" on each SocialAction, if the social action + * has at least one child + */ + public const SHOW_AND_CHILDREN = 'show_and_children'; + + public const AND_CHILDREN_MENTION = 'show_and_children_mention'; + private EngineInterface $engine; private TranslatableStringHelper $translatableStringHelper; - public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine) - { + private TranslatorInterface $translator; + + public function __construct( + TranslatableStringHelper $translatableStringHelper, + EngineInterface $engine, + TranslatorInterface $translator + ) { $this->translatableStringHelper = $translatableStringHelper; $this->engine = $engine; + $this->translator = $translator; } public function renderBox($socialAction, array $options): string @@ -72,7 +88,13 @@ class SocialActionRender implements ChillEntityRenderInterface $titles = array_reverse($titles); - return implode($options[self::SEPARATOR_KEY], $titles); + $title = implode($options[self::SEPARATOR_KEY], $titles); + + if ($options[self::SHOW_AND_CHILDREN] && $socialAction->hasChildren()) { + $title .= ' (' . $this->translator->trans($options[self::AND_CHILDREN_MENTION]) . ')'; + } + + return $title; } public function supports($entity, array $options): bool diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php index 014b23c8e..20a9c9fd2 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/SocialIssueRender.php @@ -15,7 +15,7 @@ use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Symfony\Component\Templating\EngineInterface; - +use Symfony\Contracts\Translation\TranslatorInterface; use function array_reverse; use function implode; @@ -23,18 +23,34 @@ final class SocialIssueRender implements ChillEntityRenderInterface { public const DEFAULT_ARGS = [ self::SEPARATOR_KEY => ' > ', + self::SHOW_AND_CHILDREN => false, + self::AND_CHILDREN_MENTION => 'social_issue.and children', ]; public const SEPARATOR_KEY = 'default.separator'; + /** + * Show a mention "and children" on each SocialIssue, if the social issue + * has at least one child + */ + public const SHOW_AND_CHILDREN = 'show_and_children'; + + public const AND_CHILDREN_MENTION = 'show_and_children_mention'; + private EngineInterface $engine; private TranslatableStringHelper $translatableStringHelper; - public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine) - { + private TranslatorInterface $translator; + + public function __construct( + TranslatableStringHelper $translatableStringHelper, + EngineInterface $engine, + TranslatorInterface $translator + ) { $this->translatableStringHelper = $translatableStringHelper; $this->engine = $engine; + $this->translator = $translator; } /** @@ -78,7 +94,13 @@ final class SocialIssueRender implements ChillEntityRenderInterface $titles = array_reverse($titles); - return implode($options[self::SEPARATOR_KEY], $titles); + $title = implode($options[self::SEPARATOR_KEY], $titles); + + if ($options[self::SHOW_AND_CHILDREN] && $socialIssue->hasChildren()) { + $title .= ' (' . $this->translator->trans($options[self::AND_CHILDREN_MENTION]) . ')'; + } + + return $title; } public function supports($entity, array $options): bool diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialActionTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialActionTest.php new file mode 100644 index 000000000..2e0b64d6d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialActionTest.php @@ -0,0 +1,53 @@ +setParent($parentA); + $grandChildA = (new SocialAction())->setParent($childA); + $grandGrandChildA = (new SocialAction())->setParent($grandChildA); + $unrelatedA = new SocialAction(); + + $parentB = new SocialAction(); + $childB = (new SocialAction())->setParent($parentB); + $grandChildB = (new SocialAction())->setParent($childB); + $grandGrandChildB = (new SocialAction())->setParent($grandChildB); + $unrelatedB = new SocialAction(); + + $actual = SocialAction::getDescendantsWithThisForActions([$parentA, $parentB]); + + $this->assertContains($parentA, $actual); + $this->assertContains($parentB, $actual); + $this->assertContains($childA, $actual); + $this->assertContains($childB, $actual); + $this->assertContains($grandChildA, $actual); + $this->assertContains($grandChildB, $actual); + $this->assertContains($grandGrandChildA, $actual); + $this->assertContains($grandGrandChildB, $actual); + $this->assertCount(8, $actual); + $this->assertNotContains($unrelatedA, $actual); + $this->assertNotContains($unrelatedB, $actual); + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php b/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php index edc1e5474..aee4bec07 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Entity/SocialWork/SocialIssueTest.php @@ -77,4 +77,33 @@ final class SocialIssueTest extends TestCase $this->assertFalse($child->isDescendantOf($grandChild)); } + + public function testGetDescendantsWithThisForIssues() + { + $parentA = new SocialIssue(); + $childA = (new SocialIssue())->setParent($parentA); + $grandChildA = (new SocialIssue())->setParent($childA); + $grandGrandChildA = (new SocialIssue())->setParent($grandChildA); + $unrelatedA = new SocialIssue(); + + $parentB = new SocialIssue(); + $childB = (new SocialIssue())->setParent($parentB); + $grandChildB = (new SocialIssue())->setParent($childB); + $grandGrandChildB = (new SocialIssue())->setParent($grandChildB); + $unrelatedB = new SocialIssue(); + + $actual = SocialIssue::getDescendantsWithThisForIssues([$parentA, $parentB]); + + $this->assertContains($parentA, $actual); + $this->assertContains($parentB, $actual); + $this->assertContains($childA, $actual); + $this->assertContains($childB, $actual); + $this->assertContains($grandChildA, $actual); + $this->assertContains($grandChildB, $actual); + $this->assertContains($grandGrandChildA, $actual); + $this->assertContains($grandGrandChildB, $actual); + $this->assertCount(8, $actual); + $this->assertNotContains($unrelatedA, $actual); + $this->assertNotContains($unrelatedB, $actual); + } } diff --git a/src/Bundle/ChillPersonBundle/config/services/form.yaml b/src/Bundle/ChillPersonBundle/config/services/form.yaml index 85b97c86b..52bf1f494 100644 --- a/src/Bundle/ChillPersonBundle/config/services/form.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/form.yaml @@ -27,11 +27,3 @@ services: $config: "%chill_person.accompanying_period_fields%" tags: - { name: form.type } - - Chill\PersonBundle\Form\Type\Select2SocialActionType: - autowire: true - autoconfigure: true - - Chill\PersonBundle\Form\Type\Select2SocialIssueType: - autowire: true - autoconfigure: true diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index a755ce0f0..5e4d9aada 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -951,3 +951,10 @@ export: Group course by referrer's scope: Grouper les parcours par service du référent Computation date for referrer: Date à laquelle le référent était actif Referrer's scope: Service du référent de parcours + + +social_action: + and children: et dérivés + +social_issue: + and children: et dérivés \ No newline at end of file