From 98cf16704070bb6cd23652f60ff302ea1dccf83a Mon Sep 17 00:00:00 2001 From: Christophe Siraut Date: Wed, 18 Dec 2024 18:45:27 +0100 Subject: [PATCH] ChillPersonBundle: add aggregators for administrative status and employment status --- .../AdministrativeStatusAggregator.php | 76 +++++++++++++++++++ .../EmploymentStatusAggregator.php | 76 +++++++++++++++++++ .../AdministrativeStatusRepository.php | 51 +++++++++++++ ...dministrativeStatusRepositoryInterface.php | 27 +++++++ .../Repository/EmploymentStatusRepository.php | 51 +++++++++++++ .../EmploymentStatusRepositoryInterface.php | 27 +++++++ .../config/services/exports_person.yaml | 14 ++++ .../translations/messages.fr.yml | 2 + 8 files changed, 324 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/AdministrativeStatusAggregator.php create mode 100644 src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/EmploymentStatusAggregator.php create mode 100644 src/Bundle/ChillPersonBundle/Repository/AdministrativeStatusRepository.php create mode 100644 src/Bundle/ChillPersonBundle/Repository/AdministrativeStatusRepositoryInterface.php create mode 100644 src/Bundle/ChillPersonBundle/Repository/EmploymentStatusRepository.php create mode 100644 src/Bundle/ChillPersonBundle/Repository/EmploymentStatusRepositoryInterface.php diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/AdministrativeStatusAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/AdministrativeStatusAggregator.php new file mode 100644 index 000000000..8bdc74f7f --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/AdministrativeStatusAggregator.php @@ -0,0 +1,76 @@ +leftJoin('person.administrativeStatus', 'admin_status'); + $qb->addSelect('admin_status.id as administrative_status_aggregator'); + + $qb->addGroupBy('administrative_status_aggregator'); + } + + public function applyOn() + { + return Declarations::PERSON_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) {} + + public function getFormDefaultData(): array + { + return []; + } + + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ('_header' === $value) { + return 'Administrative status'; + } + + if (null === $value || '' === $value) { + return ''; + } + + $g = $this->administrativeStatusRepository->find($value); + + return $this->translatableStringHelper->localize($g->getName()); + }; + } + + public function getQueryKeys($data) + { + return ['administrative_status_aggregator']; + } + + public function getTitle() + { + return 'Group people by administrative status'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/EmploymentStatusAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/EmploymentStatusAggregator.php new file mode 100644 index 000000000..359e48cf3 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/EmploymentStatusAggregator.php @@ -0,0 +1,76 @@ +leftJoin('person.employmentStatus', 'es'); + $qb->addSelect('es.id as employment_status_aggregator'); + + $qb->addGroupBy('employment_status_aggregator'); + } + + public function applyOn() + { + return Declarations::PERSON_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) {} + + public function getFormDefaultData(): array + { + return []; + } + + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ('_header' === $value) { + return 'Employment status'; + } + + if (null === $value || '' === $value) { + return ''; + } + + $g = $this->employmentStatusRepository->find($value); + + return $this->translatableStringHelper->localize($g->getName()); + }; + } + + public function getQueryKeys($data) + { + return ['employment_status_aggregator']; + } + + public function getTitle() + { + return 'Group people by employment status'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Repository/AdministrativeStatusRepository.php b/src/Bundle/ChillPersonBundle/Repository/AdministrativeStatusRepository.php new file mode 100644 index 000000000..40254c395 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Repository/AdministrativeStatusRepository.php @@ -0,0 +1,51 @@ +repository = $entityManager->getRepository(AdministrativeStatus::class); + } + + public function find($id): ?AdministrativeStatus + { + return $this->repository->find($id); + } + + public function findAll(): array + { + return $this->repository->findAll(); + } + + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array + { + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function findOneBy(array $criteria): ?AdministrativeStatus + { + return $this->findOneBy($criteria); + } + + public function getClassName(): string + { + return AdministrativeStatus::class; + } +} diff --git a/src/Bundle/ChillPersonBundle/Repository/AdministrativeStatusRepositoryInterface.php b/src/Bundle/ChillPersonBundle/Repository/AdministrativeStatusRepositoryInterface.php new file mode 100644 index 000000000..da40a117b --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Repository/AdministrativeStatusRepositoryInterface.php @@ -0,0 +1,27 @@ +repository = $entityManager->getRepository(EmploymentStatus::class); + } + + public function find($id): ?EmploymentStatus + { + return $this->repository->find($id); + } + + public function findAll(): array + { + return $this->repository->findAll(); + } + + public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array + { + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function findOneBy(array $criteria): ?EmploymentStatus + { + return $this->findOneBy($criteria); + } + + public function getClassName(): string + { + return EmploymentStatus::class; + } +} diff --git a/src/Bundle/ChillPersonBundle/Repository/EmploymentStatusRepositoryInterface.php b/src/Bundle/ChillPersonBundle/Repository/EmploymentStatusRepositoryInterface.php new file mode 100644 index 000000000..5d696cc9c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Repository/EmploymentStatusRepositoryInterface.php @@ -0,0 +1,27 @@ +