diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php b/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php new file mode 100644 index 000000000..d271bd3da --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php @@ -0,0 +1,138 @@ +repository = $em->getRepository(AccompanyingPeriod::class); + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // TODO: Implement buildForm() method. + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Count people participating in an accompanying course'; + } + + /** + * @inheritDoc + */ + public function getAllowedFormattersTypes(): array + { + return [FormatterInterface::TYPE_TABULAR]; + } + + /** + * @inheritDoc + */ + public function getDescription(): string + { + return 'Count people participating in an accompanying course 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->repository->createQueryBuilder('acp') + ->join('acp.participations', 'acppart') + ->join('acppart.person', 'person') + ; + + $qb->select('COUNT(DISTINCT person.id) AS export_result'); + + return $qb; + } + + /** + * @inheritDoc + */ + public function requiredRole() + { + return new Role(AccompanyingPeriodVoter::STATS); + } + + /** + * @inheritDoc + */ + public function supportsModifiers(): array + { + return [ + Declarations::ACP_TYPE, + Declarations::PERSON_TYPE + ]; + } + + public function getGroup(): string + { + return 'Exports of persons'; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml index d3bb49b6f..288cd1f15 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml @@ -7,6 +7,13 @@ services: autoconfigure: true tags: - { name: chill.export, alias: count_person } + + chill.person.export.count_person_with_accompanying_course: + class: Chill\PersonBundle\Export\Export\CountPersonWithAccompanyingCourse + autowire: true + autoconfigure: true + tags: + - { name: chill.export, alias: count_person_with_accompanying_course } chill.person.export.list_person: class: Chill\PersonBundle\Export\Export\ListPerson