From bbb167bb85a531e0e08b03e7186eb5fdae97c3b9 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 26 Feb 2024 13:36:44 +0100 Subject: [PATCH] order user jobs alphabetically when returning all active user jobs --- .../ChillActivityBundle/Export/Filter/CreatorJobFilter.php | 2 +- .../ChillActivityBundle/Export/Filter/UsersJobFilter.php | 5 ++++- .../src/Export/Filter/ByUserJobFilter.php | 5 ++++- src/Bundle/ChillCalendarBundle/Export/Filter/JobFilter.php | 5 ++++- src/Bundle/ChillEventBundle/Controller/EventController.php | 1 + src/Bundle/ChillMainBundle/Repository/UserJobRepository.php | 6 +++++- .../AccompanyingCourseFilters/JobWorkingOnCourseFilter.php | 5 +---- .../Export/Filter/SocialWorkFilters/JobFilter.php | 5 ++++- 8 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/CreatorJobFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/CreatorJobFilter.php index 6ce340874..c43edb666 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/CreatorJobFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/CreatorJobFilter.php @@ -80,7 +80,7 @@ final readonly class CreatorJobFilter implements FilterInterface { $builder ->add('jobs', EntityType::class, [ - 'choices' => $this->userJobRepository->findAllOrderedByName(), + 'choices' => $this->userJobRepository->findAllActive(), 'class' => UserJob::class, 'choice_label' => fn (UserJob $s) => $this->translatableStringHelper->localize( $s->getLabel() diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/UsersJobFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/UsersJobFilter.php index ae21482fc..0987e7ae9 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/UsersJobFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/UsersJobFilter.php @@ -16,6 +16,7 @@ use Chill\ActivityBundle\Export\Declarations; use Chill\MainBundle\Entity\User\UserJobHistory; use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Repository\UserJobRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; @@ -27,7 +28,8 @@ class UsersJobFilter implements FilterInterface private const PREFIX = 'act_filter_user_job'; public function __construct( - private readonly TranslatableStringHelperInterface $translatableStringHelper + private readonly TranslatableStringHelperInterface $translatableStringHelper, + private readonly UserJobRepositoryInterface $userJobRepository ) { } @@ -69,6 +71,7 @@ class UsersJobFilter implements FilterInterface $builder ->add('jobs', EntityType::class, [ 'class' => UserJob::class, + 'choices' => $this->userJobRepository->findAllActive(), 'choice_label' => fn (UserJob $j) => $this->translatableStringHelper->localize($j->getLabel()), 'multiple' => true, 'expanded' => true, diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByUserJobFilter.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByUserJobFilter.php index 2418f5428..691e708c6 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByUserJobFilter.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByUserJobFilter.php @@ -16,6 +16,7 @@ use Chill\AsideActivityBundle\Export\Declarations; use Chill\MainBundle\Entity\User\UserJobHistory; use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Repository\UserJobRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; @@ -27,7 +28,8 @@ class ByUserJobFilter implements FilterInterface private const PREFIX = 'aside_act_filter_user_job'; public function __construct( - private readonly TranslatableStringHelperInterface $translatableStringHelper + private readonly TranslatableStringHelperInterface $translatableStringHelper, + private readonly UserJobRepositoryInterface $userJobRepository ) { } @@ -69,6 +71,7 @@ class ByUserJobFilter implements FilterInterface $builder ->add('jobs', EntityType::class, [ 'class' => UserJob::class, + 'choices' => $this->userJobRepository->findAllActive(), 'choice_label' => fn (UserJob $j) => $this->translatableStringHelper->localize($j->getLabel()), 'multiple' => true, 'expanded' => true, diff --git a/src/Bundle/ChillCalendarBundle/Export/Filter/JobFilter.php b/src/Bundle/ChillCalendarBundle/Export/Filter/JobFilter.php index 6b81a709f..b2b5e6a12 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Filter/JobFilter.php +++ b/src/Bundle/ChillCalendarBundle/Export/Filter/JobFilter.php @@ -15,6 +15,7 @@ use Chill\CalendarBundle\Export\Declarations; use Chill\MainBundle\Entity\User\UserJobHistory; use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Repository\UserJobRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; @@ -26,7 +27,8 @@ final readonly class JobFilter implements FilterInterface private const PREFIX = 'cal_filter_job'; public function __construct( - private TranslatableStringHelper $translatableStringHelper + private TranslatableStringHelper $translatableStringHelper, + private UserJobRepositoryInterface $userJobRepository ) { } @@ -74,6 +76,7 @@ final readonly class JobFilter implements FilterInterface $builder ->add('job', EntityType::class, [ 'class' => UserJob::class, + 'choices' => $this->userJobRepository->findAllActive(), 'choice_label' => fn (UserJob $j) => $this->translatableStringHelper->localize( $j->getLabel() ), diff --git a/src/Bundle/ChillEventBundle/Controller/EventController.php b/src/Bundle/ChillEventBundle/Controller/EventController.php index 7cbd2fbbe..e49c02c06 100644 --- a/src/Bundle/ChillEventBundle/Controller/EventController.php +++ b/src/Bundle/ChillEventBundle/Controller/EventController.php @@ -433,6 +433,7 @@ final class EventController extends AbstractController $builder->add('event_id', HiddenType::class, [ 'data' => $event->getId(), ]); + dump($event->getId()); return $builder->getForm(); } diff --git a/src/Bundle/ChillMainBundle/Repository/UserJobRepository.php b/src/Bundle/ChillMainBundle/Repository/UserJobRepository.php index 3c92c7f60..6b793a2c8 100644 --- a/src/Bundle/ChillMainBundle/Repository/UserJobRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/UserJobRepository.php @@ -40,7 +40,11 @@ readonly class UserJobRepository implements UserJobRepositoryInterface public function findAllActive(): array { - return $this->repository->findBy(['active' => true]); + $jobs = $this->repository->findBy(['active' => true]); + + usort($jobs, fn (UserJob $a, UserJob $b) => $this->translatableStringHelper->localize($a->getLabel()) <=> $this->translatableStringHelper->localize($b->getLabel())); + + return $jobs; } public function findAllOrderedByName(): array diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php index 8ba1b585d..73d5a02c9 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php @@ -84,13 +84,10 @@ readonly class JobWorkingOnCourseFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder): void { - $jobs = $this->userJobRepository->findAllActive(); - usort($jobs, fn (UserJob $a, UserJob $b) => $this->translatableStringHelper->localize($a->getLabel()) <=> $this->translatableStringHelper->localize($b->getLabel())); - $builder ->add('jobs', EntityType::class, [ 'class' => UserJob::class, - 'choices' => $jobs, + 'choices' => $this->userJobRepository->findAllActive(), 'choice_label' => fn (UserJob $userJob) => $this->translatableStringHelper->localize($userJob->getLabel()), 'multiple' => true, 'expanded' => true, diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/JobFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/JobFilter.php index 4622f61f9..bb54f288b 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/JobFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/JobFilter.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Filter\SocialWorkFilters; use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Repository\UserJobRepositoryInterface; use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkReferrerHistory; @@ -28,7 +29,8 @@ class JobFilter implements FilterInterface public function __construct( protected TranslatorInterface $translator, - private readonly TranslatableStringHelper $translatableStringHelper + private readonly TranslatableStringHelper $translatableStringHelper, + private readonly UserJobRepositoryInterface $userJobRepository, ) { } @@ -61,6 +63,7 @@ class JobFilter implements FilterInterface $builder ->add('job', EntityType::class, [ 'class' => UserJob::class, + 'choices' => $this->userJobRepository->findAllActive(), 'choice_label' => fn (UserJob $j) => $this->translatableStringHelper->localize( $j->getLabel() ),