diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php new file mode 100644 index 000000000..edf4dc24c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php @@ -0,0 +1,99 @@ + 1 mois, + * - jusqu'à 45 jours => 1 mois, + * 15 | 45 | 75 + * --+----o----+----o----+---- + * | 30 | 60 | + * etc.) + */ +class DurationAggregator implements AggregatorInterface +{ + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + return function ($value): string { + switch ($value) { + + case '_header': + return 'Duration'; + + + default: + throw new \LogicException(sprintf('The value %s is not valid', $value)); + } + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['duration_aggregator']; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Group by duration'; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb + ->addSelect('(acp.closingDate - acp.openingDate) AS duration_aggregator') + ; + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('duration_aggregator'); + } else { + $qb->groupBy('duration_aggregator'); + } + + $qb->orderBy('duration_aggregator'); + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml index 155ad11df..2b578b4f9 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml @@ -241,3 +241,10 @@ services: tags: - { name: chill.export_aggregator, alias: accompanyingcourse_referrer_aggregator } + chill.person.export.aggregator_duration: + class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\DurationAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: accompanyingcourse_duration_aggregator } + diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 9bb2c7e3f..fdddd5c6c 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -569,6 +569,7 @@ Group by composition: Grouper les ménages par composition familiale Group by number of children: Grouper les ménages par nombre d'enfants ## persons aggregators +Group by duration: Grouper par durée du parcours Group people by nationality: Grouper les personnes par nationalités Group by level: Grouper par niveau Group by continents: Grouper par continent