diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersJobAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersJobAggregator.php index 6f05d88f6..8e2b41025 100644 --- a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersJobAggregator.php +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersJobAggregator.php @@ -12,15 +12,26 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Export\Aggregator; use Chill\ActivityBundle\Export\Declarations; +use Chill\MainBundle\Entity\User\UserJobHistory; +use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Repository\UserJobRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverter; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; -use function in_array; -class ActivityUsersJobAggregator implements \Chill\MainBundle\Export\AggregatorInterface +class ActivityUsersJobAggregator implements AggregatorInterface { - public function __construct(private readonly UserJobRepositoryInterface $userJobRepository, private readonly TranslatableStringHelperInterface $translatableStringHelper) {} + private const PREFIX = 'act_agg_user_job'; + + public function __construct( + private readonly RollingDateConverter $rollingDateConverter, + private readonly UserJobRepositoryInterface $userJobRepository, + private readonly TranslatableStringHelperInterface $translatableStringHelper + ) {} public function addRole(): ?string { @@ -29,27 +40,48 @@ class ActivityUsersJobAggregator implements \Chill\MainBundle\Export\AggregatorI public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('actusers', $qb->getAllAliases(), true)) { - $qb->leftJoin('activity.users', 'actusers'); - } + $p = self::PREFIX; $qb - ->addSelect('IDENTITY(actusers.userJob) AS activity_users_job_aggregator') - ->addGroupBy('activity_users_job_aggregator'); + ->leftJoin("activity.users", "{$p}_user") + ->leftJoin( + UserJobHistory::class, + "{$p}_history", + Expr\Join::WITH, + $qb->expr()->eq("{$p}_history.user", "{$p}_user") + ) + ->andWhere( + $qb->expr()->andX( + $qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"), + $qb->expr()->orX( + $qb->expr()->isNull("{$p}_history.endDate"), + $qb->expr()->gt("{$p}_history.endDate", ":{$p}_at") + ) + ) + ) + ->addSelect("IDENTITY({$p}_history.job) AS {$p}_select") + ->setParameter( + "{$p}_at", $this->rollingDateConverter->convert($data['job_at']) + ) + ->addGroupBy("{$p}_select"); } - public function applyOn() + public function applyOn(): string { return Declarations::ACTIVITY; } public function buildForm(FormBuilderInterface $builder) { - // nothing to add in the form + $builder->add('job_at', PickRollingDateType::class, [ + 'label' => 'export.aggregator.activity.by_user_job.Calc date', + 'required' => true + ]); + } public function getFormDefaultData(): array { - return []; + return ['job_at' => new RollingDate(RollingDate::T_TODAY)]; } public function getLabels($key, array $values, $data) @@ -73,11 +105,11 @@ class ActivityUsersJobAggregator implements \Chill\MainBundle\Export\AggregatorI public function getQueryKeys($data): array { - return ['activity_users_job_aggregator']; + return [self::PREFIX . '_select']; } - public function getTitle() + public function getTitle(): string { - return 'Aggregate by users job'; + return 'export.aggregator.activity.by_user_job.Aggregate by users job'; } } diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersScopeAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersScopeAggregator.php index a29458dc7..3d05af976 100644 --- a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersScopeAggregator.php +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityUsersScopeAggregator.php @@ -12,15 +12,26 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Export\Aggregator; use Chill\ActivityBundle\Export\Declarations; +use Chill\MainBundle\Entity\User\UserScopeHistory; +use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Repository\ScopeRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverter; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; -use function in_array; -class ActivityUsersScopeAggregator implements \Chill\MainBundle\Export\AggregatorInterface +class ActivityUsersScopeAggregator implements AggregatorInterface { - public function __construct(private readonly ScopeRepositoryInterface $scopeRepository, private readonly TranslatableStringHelperInterface $translatableStringHelper) {} + private const PREFIX = 'act_agg_user_scope'; + + public function __construct( + private readonly RollingDateConverter $rollingDateConverter, + private readonly ScopeRepositoryInterface $scopeRepository, + private readonly TranslatableStringHelperInterface $translatableStringHelper + ) {} public function addRole(): ?string { @@ -29,27 +40,47 @@ class ActivityUsersScopeAggregator implements \Chill\MainBundle\Export\Aggregato public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('actusers', $qb->getAllAliases(), true)) { - $qb->leftJoin('activity.users', 'actusers'); - } + $p = self::PREFIX; $qb - ->addSelect('IDENTITY(actusers.mainScope) AS activity_users_main_scope_aggregator') - ->addGroupBy('activity_users_main_scope_aggregator'); + ->leftJoin("activity.users", "{$p}_user") + ->leftJoin( + UserScopeHistory::class, + "{$p}_history", + Expr\Join::WITH, + $qb->expr()->eq("{$p}_history.user", "{$p}_user") + ) + ->andWhere( + $qb->expr()->andX( + $qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"), + $qb->expr()->orX( + $qb->expr()->isNull("{$p}_history.endDate"), + $qb->expr()->gt("{$p}_history.endDate", ":{$p}_at") + ) + ) + ) + ->addSelect("IDENTITY({$p}_history.scope) AS {$p}_select") + ->setParameter( + "{$p}_at", $this->rollingDateConverter->convert($data['scope_at']) + ) + ->addGroupBy("{$p}_select"); } - public function applyOn() + public function applyOn(): string { return Declarations::ACTIVITY; } public function buildForm(FormBuilderInterface $builder) { - // nothing to add in the form + $builder->add('scope_at', PickRollingDateType::class, [ + 'label' => 'export.aggregator.activity.by_user_scope.Calc date', + 'required' => true, + ]); } public function getFormDefaultData(): array { - return []; + return ['scope_at' => new RollingDate(RollingDate::T_TODAY)]; } public function getLabels($key, array $values, $data) @@ -73,11 +104,11 @@ class ActivityUsersScopeAggregator implements \Chill\MainBundle\Export\Aggregato public function getQueryKeys($data): array { - return ['activity_users_main_scope_aggregator']; + return [self::PREFIX . '_select']; } - public function getTitle() + public function getTitle(): string { - return 'Aggregate by users scope'; + return 'export.aggregator.activity.by_user_scope.Aggregate by users scope'; } } diff --git a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml index ef2494f57..b824b7a56 100644 --- a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml @@ -306,10 +306,6 @@ Aggregate by activity user: Grouper les échanges par référent Aggregate by activity users: Grouper les échanges par utilisateurs participants Aggregate by activity type: Grouper les échanges par type Aggregate by activity reason: Grouper les échanges par sujet -Aggregate by users scope: Grouper les échanges par service principal de l'utilisateur -Users 's scope: Service principal des utilisateurs participants à l'échange -Aggregate by users job: Grouper les échanges par métier des utilisateurs participants -Users 's job: Métier des utilisateurs participants à l'échange Group activity by locationtype: Grouper les échanges par type de localisation Group activity by date: Grouper les échanges par date @@ -391,6 +387,15 @@ export: by_location: Activity Location: Localisation de l'échange Title: Grouper les échanges par localisation de l'échange + by_user_job: + Users 's job: Métier des utilisateurs participants à l'échange + Aggregate by users job: Grouper les échanges par métier des utilisateurs participants + Calc date: Date de calcul du métier des participants + by_user_scope: + Users 's scope: Service principal des utilisateurs participants à l'échange + Aggregate by users scope: Grouper les échanges par service principal de l'utilisateur + Calc date: Date de calcul du service principal de l'utilisateur + generic_doc: filter: diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByUserJobAggregator.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByUserJobAggregator.php index 474f0a49f..4be1aa669 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByUserJobAggregator.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByUserJobAggregator.php @@ -12,9 +12,14 @@ declare(strict_types=1); namespace Chill\AsideActivityBundle\Export\Aggregator; use Chill\AsideActivityBundle\Export\Declarations; +use Chill\MainBundle\Entity\User\UserJobHistory; use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Repository\UserJobRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverter; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -22,7 +27,13 @@ use function in_array; class ByUserJobAggregator implements AggregatorInterface { - public function __construct(private readonly UserJobRepositoryInterface $userJobRepository, private readonly TranslatableStringHelperInterface $translatableStringHelper) {} + private const PREFIX = 'aside_act_agg_user_job'; + + public function __construct( + private readonly RollingDateConverter $rollingDateConverter, + private readonly UserJobRepositoryInterface $userJobRepository, + private readonly TranslatableStringHelperInterface $translatableStringHelper + ) {} public function addRole(): ?string { @@ -31,27 +42,47 @@ class ByUserJobAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('aside_user', $qb->getAllAliases(), true)) { - $qb->leftJoin('aside.agent', 'aside_user'); - } + $p = self::PREFIX; $qb - ->addSelect('IDENTITY(aside_user.userJob) AS aside_activity_user_job_aggregator') - ->addGroupBy('aside_activity_user_job_aggregator'); + ->leftJoin("aside.agent", "{$p}_user") + ->leftJoin( + UserJobHistory::class, + "{$p}_history", + Expr\Join::WITH, + $qb->expr()->eq("{$p}_history.user", "{$p}_user") + ) + ->andWhere( + $qb->expr()->andX( + $qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"), + $qb->expr()->orX( + $qb->expr()->isNull("{$p}_history.endDate"), + $qb->expr()->gt("{$p}_history.endDate", ":{$p}_at") + ) + ) + ) + ->addSelect("IDENTITY({$p}_history.job) AS {$p}_select") + ->setParameter( + "{$p}_at", $this->rollingDateConverter->convert($data['job_at']) + ) + ->addGroupBy("{$p}_select"); } - public function applyOn() + public function applyOn(): string { return Declarations::ASIDE_ACTIVITY_TYPE; } public function buildForm(FormBuilderInterface $builder) { - // nothing to add in the form + $builder->add('job_at', PickRollingDateType::class, [ + 'label' => 'export.aggregator.by_user_job.Calc date', + 'required' => true + ]); } public function getFormDefaultData(): array { - return []; + return ['job_at' => new RollingDate(RollingDate::T_TODAY)]; } public function getLabels($key, array $values, $data) @@ -75,11 +106,11 @@ class ByUserJobAggregator implements AggregatorInterface public function getQueryKeys($data): array { - return ['aside_activity_user_job_aggregator']; + return [self::PREFIX . '_select']; } - public function getTitle() + public function getTitle(): string { - return 'export.aggregator.Aggregate by user job'; + return 'export.aggregator.by_user_job.Aggregate by user job'; } } diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByUserScopeAggregator.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByUserScopeAggregator.php index 03646fab4..fc8a8cbab 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByUserScopeAggregator.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Aggregator/ByUserScopeAggregator.php @@ -12,17 +12,26 @@ declare(strict_types=1); namespace Chill\AsideActivityBundle\Export\Aggregator; use Chill\AsideActivityBundle\Export\Declarations; +use Chill\MainBundle\Entity\User\UserScopeHistory; use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Repository\ScopeRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverter; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; -use function in_array; - class ByUserScopeAggregator implements AggregatorInterface { - public function __construct(private readonly ScopeRepositoryInterface $scopeRepository, private readonly TranslatableStringHelperInterface $translatableStringHelper) {} + private const PREFIX = 'aside_act_agg_user_scope'; + + public function __construct( + private readonly RollingDateConverter $rollingDateConverter, + private readonly ScopeRepositoryInterface $scopeRepository, + private readonly TranslatableStringHelperInterface $translatableStringHelper + ) {} public function addRole(): ?string { @@ -31,27 +40,47 @@ class ByUserScopeAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('aside_user', $qb->getAllAliases(), true)) { - $qb->leftJoin('aside.agent', 'aside_user'); - } + $p = self::PREFIX; $qb - ->addSelect('IDENTITY(aside_user.mainScope) AS aside_activity_user_scope_aggregator') - ->addGroupBy('aside_activity_user_scope_aggregator'); + ->leftJoin("aside.agent", "{$p}_user") + ->leftJoin( + UserScopeHistory::class, + "{$p}_history", + Expr\Join::WITH, + $qb->expr()->eq("{$p}_history.user", "{$p}_user") + ) + ->andWhere( + $qb->expr()->andX( + $qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"), + $qb->expr()->orX( + $qb->expr()->isNull("{$p}_history.endDate"), + $qb->expr()->gt("{$p}_history.endDate", ":{$p}_at") + ) + ) + ) + ->addSelect("IDENTITY({$p}_history.scope) AS {$p}_select") + ->setParameter( + "{$p}_at", $this->rollingDateConverter->convert($data['scope_at']) + ) + ->addGroupBy("{$p}_select"); } - public function applyOn() + public function applyOn(): string { return Declarations::ASIDE_ACTIVITY_TYPE; } public function buildForm(FormBuilderInterface $builder) { - // nothing to add in the form + $builder->add('scope_at', PickRollingDateType::class, [ + 'label' => 'export.aggregator.by_user_scope.Calc date', + 'required' => true, + ]); } public function getFormDefaultData(): array { - return []; + return ['scope_at' => new RollingDate(RollingDate::T_TODAY)]; } public function getLabels($key, array $values, $data) @@ -75,11 +104,11 @@ class ByUserScopeAggregator implements AggregatorInterface public function getQueryKeys($data): array { - return ['aside_activity_user_scope_aggregator']; + return [self::PREFIX . '_select']; } - public function getTitle() + public function getTitle(): string { - return 'export.aggregator.Aggregate by user scope'; + return 'export.aggregator.by_user_scope.Aggregate by user scope'; } } diff --git a/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml b/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml index 6028193db..69f4e8736 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml +++ b/src/Bundle/ChillAsideActivityBundle/src/translations/messages.fr.yml @@ -209,8 +209,12 @@ export: aggregator: Group by aside activity type: Grouper les activités annexes par type d'activité Aside activity type: Type d'activité annexe - Aggregate by user job: Grouper les activités annexes par métier des utilisateurs - Aggregate by user scope: Grouper les activités annexes par service des utilisateurs + by_user_job: + Aggregate by user job: Grouper les activités annexes par métier des utilisateurs + Calc date: Date de calcul du métier des utilisateurs + by_user_scope: + Aggregate by user scope: Grouper les activités annexes par service des utilisateurs + Calc date: Date de calcul du service des utilisateurs Aside activity location: Localisation des activités annexe Group by aside activity location: Grouper les activités annexes par localisation Aside activity localisation: Localisation