From a06a2c9592f65e742cc7e06d06ae4f4af27f73de Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 26 Jul 2022 10:41:24 +0200 Subject: [PATCH] start of social actions export --- .../ChillPersonBundle/Export/Declarations.php | 2 + .../Export/Export/CountSocialActions.php | 107 ++++++++++++++++++ .../SocialWork/SocialActionRepository.php | 6 + .../config/services/exports.yaml | 25 ++-- .../translations/messages.fr.yml | 2 + 5 files changed, 132 insertions(+), 10 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Export/Export/CountSocialActions.php diff --git a/src/Bundle/ChillPersonBundle/Export/Declarations.php b/src/Bundle/ChillPersonBundle/Export/Declarations.php index bb892a69c..8cc82e7ea 100644 --- a/src/Bundle/ChillPersonBundle/Export/Declarations.php +++ b/src/Bundle/ChillPersonBundle/Export/Declarations.php @@ -21,4 +21,6 @@ abstract class Declarations public const PERSON_TYPE = 'person'; public const ACP_TYPE = 'accompanying_period'; + + public const SOCIAL_ACTION_TYPE = 'social_actions'; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountSocialActions.php b/src/Bundle/ChillPersonBundle/Export/Export/CountSocialActions.php new file mode 100644 index 000000000..b9c2dd746 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountSocialActions.php @@ -0,0 +1,107 @@ +socialActionRepository = $socialActionRepository; + } + + public function buildForm(FormBuilderInterface $builder): void + { + // TODO: Implement buildForm() method. + } + + public function getTitle(): string + { + return 'Count social actions'; + } + + public function getAllowedFormattersTypes(): array + { + return [FormatterInterface::TYPE_TABULAR]; + } + + public function getDescription(): string + { + return 'Count social actions by various parameters'; + } + + public function getLabels($key, array $values, $data) + { + if ('export_count_social_actions' !== $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]; + }; + } + + public function getQueryKeys($data): array + { + return ['export_count_social_actions']; + } + + public function getResult($qb, $data) + { + return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); + } + + public function getType(): string + { + return Declarations::SOCIAL_ACTION_TYPE; + } + + public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder + { + $qb = $this + ->socialActionRepository + ->createQueryBuilder('sa') + ->select('COUNT(sa.id) as export_count_social_actions'); + + return $qb; + } + + public function requiredRole(): string + { + return AccompanyingPeriodVoter::STATS; + } + + public function supportsModifiers(): array + { + return [Declarations::SOCIAL_ACTION_TYPE]; + } + + public function getGroup(): string + { + return 'Exports of social actions'; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php index fdf9d3b3f..4d9597f83 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php @@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ObjectRepository; final class SocialActionRepository implements ObjectRepository @@ -25,6 +26,11 @@ final class SocialActionRepository implements ObjectRepository $this->repository = $entityManager->getRepository(SocialAction::class); } + public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder + { + return $this->repository->createQueryBuilder($alias, $indexBy); + } + public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?SocialAction { return $this->repository->find($id, $lockMode, $lockVersion); diff --git a/src/Bundle/ChillPersonBundle/config/services/exports.yaml b/src/Bundle/ChillPersonBundle/config/services/exports.yaml index 4cf752870..9c5638431 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports.yaml @@ -27,18 +27,23 @@ services: - { name: chill.export, alias: list_person_duplicate } chill.person.export.count_accompanyingcourse: - class: Chill\PersonBundle\Export\Export\CountAccompanyingCourse - arguments: - - "@doctrine.orm.entity_manager" - tags: - - { name: chill.export, alias: count_accompanyingcourse } + class: Chill\PersonBundle\Export\Export\CountAccompanyingCourse + arguments: + - "@doctrine.orm.entity_manager" + tags: + - { name: chill.export, alias: count_accompanyingcourse } chill.person.export.avg_accompanyingcourse_duration: - class: Chill\PersonBundle\Export\Export\StatAccompanyingCourseDuration - arguments: - - '@Chill\PersonBundle\Repository\AccompanyingPeriodRepository' - tags: - - { name: chill.export, alias: avg_accompanyingcourse_duration } + class: Chill\PersonBundle\Export\Export\StatAccompanyingCourseDuration + arguments: + - '@Chill\PersonBundle\Repository\AccompanyingPeriodRepository' + tags: + - { name: chill.export, alias: avg_accompanyingcourse_duration } + + chill.person.export.count_social_actions: + class: Chill\PersonBundle\Export\Export\CountSocialActions + autowire: true + autoconfigure: true chill.person.export.filter_gender: class: Chill\PersonBundle\Export\Filter\GenderFilter diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 122571198..c764817b3 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -340,7 +340,9 @@ Create a list of duplicate people: Créer la liste des personnes détectées com Exports of accompanying courses: Exports des parcours d'accompagnement Count accompanying courses: Nombre de parcours +Count social actions: Nombre d'actions d'accompagnement Count accompanying courses by various parameters: Compte le nombre de parcours en fonction de différents filtres. +Count social actions by various parameters: Compte le nombre d'actions d'accompagnement en fonction de différents filtres. Accompanying courses duration: Durée moyenne des parcours Create an average of accompanying courses duration according to various filters: Moyenne de la durée des parcours en jours, selon différents filtres. Closingdate to apply: Date de fin à prendre en compte lorsque le parcours n'est pas clotûré