diff --git a/src/Bundle/ChillPersonBundle/Export/Declarations.php b/src/Bundle/ChillPersonBundle/Export/Declarations.php index 8cc82e7ea..dc5c3f971 100644 --- a/src/Bundle/ChillPersonBundle/Export/Declarations.php +++ b/src/Bundle/ChillPersonBundle/Export/Declarations.php @@ -22,5 +22,5 @@ abstract class Declarations public const ACP_TYPE = 'accompanying_period'; - public const SOCIAL_ACTION_TYPE = 'social_actions'; + public const SOCIAL_WORK_ACTION_TYPE = 'social_actions'; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountSocialActions.php b/src/Bundle/ChillPersonBundle/Export/Export/CountSocialWorkActions.php similarity index 70% rename from src/Bundle/ChillPersonBundle/Export/Export/CountSocialActions.php rename to src/Bundle/ChillPersonBundle/Export/Export/CountSocialWorkActions.php index a41f4a6d2..a7086271a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountSocialActions.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountSocialWorkActions.php @@ -15,7 +15,7 @@ use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\PersonBundle\Export\Declarations; -use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository; +use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; @@ -23,23 +23,23 @@ use Symfony\Component\Form\FormBuilderInterface; use LogicException; use Symfony\Component\Security\Core\Role\Role; -class CountSocialActions implements ExportInterface, GroupedExportInterface +class CountSocialWorkActions implements ExportInterface, GroupedExportInterface { - protected SocialActionRepository $socialActionRepository; + protected AccompanyingPeriodWorkRepository $socialActionRepository; - public function __construct(SocialActionRepository $socialActionRepository) + public function __construct(AccompanyingPeriodWorkRepository $socialActionRepository) { $this->socialActionRepository = $socialActionRepository; } public function buildForm(FormBuilderInterface $builder): void { - // TODO: Implement buildForm() method. + // No form necessary? } public function getTitle(): string { - return 'Count social actions'; + return 'Count social work actions'; } public function getAllowedFormattersTypes(): array @@ -49,12 +49,12 @@ class CountSocialActions implements ExportInterface, GroupedExportInterface public function getDescription(): string { - return 'Count social actions by various parameters'; + return 'Count social work actions by various parameters'; } public function getLabels($key, array $values, $data) { - if ('export_count_social_actions' !== $key) { + if ('export_count_social_work_actions' !== $key) { throw new LogicException("the key {$key} is not used by this export"); } @@ -68,7 +68,7 @@ class CountSocialActions implements ExportInterface, GroupedExportInterface public function getQueryKeys($data): array { - return ['export_count_social_actions']; + return ['export_count_social_work_actions']; } public function getResult($qb, $data) @@ -78,32 +78,32 @@ class CountSocialActions implements ExportInterface, GroupedExportInterface public function getType(): string { - return Declarations::SOCIAL_ACTION_TYPE; + return Declarations::SOCIAL_WORK_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'); + ->createQueryBuilder('acpw') + ->select('COUNT(acpw.id) as export_count_social_work_actions'); return $qb; } public function requiredRole(): Role { - //TODO change to string, but changes needed also in exportManager and possibly other locations. + //TODO change to string, but changes needed also in ExportManager and possibly other locations. return new Role(AccompanyingPeriodVoter::STATS); } public function supportsModifiers(): array { - return [Declarations::SOCIAL_ACTION_TYPE]; + return [Declarations::SOCIAL_WORK_ACTION_TYPE]; } public function getGroup(): string { - return 'Exports of social actions'; + return 'Exports of social work actions'; } } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php new file mode 100644 index 000000000..678feee80 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php @@ -0,0 +1,77 @@ +userRender = $userRender; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('users', EntityType::class, [ + 'class' => User::class, + 'choice_label' => function (User $u) { + $this->userRender->renderString($u, []); + }, + 'multiple' => true, + 'expanded' => true + ]); + } + + public function getTitle(): string + { + return 'Filter by referrers'; + } + + public function describeAction($data, $format = 'string'): array + { + $users = []; + + foreach ($data['users'] as $u) { + $users[] = $u->getUsername(); + } + + return ['Filtered by users: only %users%', [ + '%user%' => implode(', ou ', $users) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('acpw.referrers', ':users'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('users', $data['users']); + } + + public function applyOn(): string + { + return Declarations::SOCIAL_WORK_ACTION_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php index dd27cf434..c2826485e 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php @@ -35,6 +35,11 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository $this->repository = $entityManager->getRepository(AccompanyingPeriodWork::class); } + public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder + { + return $this->repository->createQueryBuilder($alias, $indexBy); + } + public function countByAccompanyingPeriod(AccompanyingPeriod $period): int { return $this->repository->countByAccompanyingPeriod($period); diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml index 1892e9962..8936af9b9 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml @@ -1,7 +1,15 @@ services: - chill.person.export.count_social_actions: - class: Chill\PersonBundle\Export\Export\CountSocialActions + + chill.person.export.count_social_work_actions: + class: Chill\PersonBundle\Export\Export\CountSocialWorkActions autowire: true autoconfigure: true tags: - - { name: chill.export, alias: count_social_actions } \ No newline at end of file + - { name: chill.export, alias: count_social_work_actions } + + chill.person.export.filter_referrers: + class: Chill\PersonBundle\Export\Filter\ReferrerFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: social_work_actions_referrer_filter } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 616f02366..ca7a27e1c 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -345,9 +345,9 @@ 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é -Exports of social actions: Exports des actions d'accompangement -Count social actions: Nombre d'actions d'accompagnement -Count social actions by various parameters: Compte le nombre d'actions d'accompagnement en fonction de différents filtres. +Exports of social work actions: Exports des actions d'accompangement +Count social work actions: Nombre d'actions d'accompagnement +Count social work actions by various parameters: Compte le nombre d'actions d'accompagnement en fonction de différents filtres. ## filters Filter by person gender: Filtrer par genre de la personne