From 3f4d4497af46148f8919f23cc37928a024715061 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 10 Aug 2022 14:03:47 +0200 Subject: [PATCH] exports: add new countHousehold export --- .../ChillPersonExtension.php | 1 + .../ChillPersonBundle/Export/Declarations.php | 2 + .../Export/Export/CountHousehold.php | 139 ++++++++++++++++++ .../config/services/exports_household.yaml | 13 ++ .../translations/messages.fr.yml | 4 + 5 files changed, 159 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php create mode 100644 src/Bundle/ChillPersonBundle/config/services/exports_household.yaml diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index bf73b4f81..efbb972c1 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -101,6 +101,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac $loader->load('services/exports_accompanying_course.yaml'); $loader->load('services/exports_social_actions.yaml'); $loader->load('services/exports_evaluation.yaml'); + $loader->load('services/exports_household.yaml'); } /** diff --git a/src/Bundle/ChillPersonBundle/Export/Declarations.php b/src/Bundle/ChillPersonBundle/Export/Declarations.php index 5a88d988b..b8e2cd69c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Declarations.php +++ b/src/Bundle/ChillPersonBundle/Export/Declarations.php @@ -27,4 +27,6 @@ abstract class Declarations public const SOCIAL_WORK_ACTION_TYPE = 'social_actions'; public const EVAL_TYPE = 'evaluation'; + + public const HOUSEHOLD_TYPE = 'household'; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php b/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php new file mode 100644 index 000000000..0fa708bf0 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php @@ -0,0 +1,139 @@ +acpRepository = $em->getRepository(AccompanyingPeriod::class); + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // TODO: Implement buildForm() method. + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Count households'; + } + + /** + * @inheritDoc + */ + public function getAllowedFormattersTypes(): array + { + return [FormatterInterface::TYPE_TABULAR]; + } + + /** + * @inheritDoc + */ + public function getDescription(): string + { + return 'Count household by various parameters.'; + } + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + if ('export_result' !== $key) { + throw new LogicException("the key {$key} is not used by this export"); + } + + $labels = array_combine($values, $values); + $labels['_header'] = $this->getTitle(); + + return static function ($value) use ($labels) { + return $labels[$value]; + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['export_result']; + } + + /** + * @inheritDoc + */ + public function getResult($qb, $data) + { + return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); + } + + /** + * @inheritDoc + */ + public function getType(): string + { + return Declarations::HOUSEHOLD_TYPE; + } + + /** + * @inheritDoc + */ + public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) + { + $qb = $this->acpRepository->createQueryBuilder('acp') + ->join('acp.participations', 'acppart') + ->join('acppart.person', 'person') + ->join('person.householdParticipations', 'householdmember') + ; + + $qb->select('COUNT(DISTINCT householdmember.household) AS export_result'); + + return $qb; + } + + /** + * @inheritDoc + */ + public function requiredRole() + { + // TODO HouseholdVoter::STATS !?? + return new Role(AccompanyingPeriodVoter::STATS); + } + + /** + * @inheritDoc + */ + public function supportsModifiers(): array + { + return [ + Declarations::HOUSEHOLD_TYPE, + ]; + } + + public function getGroup(): string + { + return 'Exports of households'; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_household.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_household.yaml new file mode 100644 index 000000000..45d70f6e4 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/config/services/exports_household.yaml @@ -0,0 +1,13 @@ +services: + + ## Indicators + chill.person.export.count_household: + class: Chill\PersonBundle\Export\Export\CountHousehold + autowire: true + autoconfigure: true + tags: + - { name: chill.export, alias: count_household } + + ## Filters + + ## Aggregators diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index af21991d3..2f783c1e7 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -354,6 +354,10 @@ Exports of evaluations: Exports des évaluations Count evaluations: Nombre d'évaluations Count evaluation by various parameters.: Compte le nombre d'évaluations selon différents filtres. +Exports of households: Exports des ménages +Count households: Nombre de ménages +Count household by various parameters.: Compte le nombre de ménages selon différents filtres. + ## filters Filter by person gender: Filtrer par genre de la personne Accepted genders: Genres acceptés