diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php index 801e5d799..abd9feffb 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php @@ -77,8 +77,8 @@ readonly class ReferrerScopeAggregator implements AggregatorInterface "{$p}_date_calc", $this->rollingDateConverter->convert($data['date_calc']) ) - ->addSelect("IDENTITY({$p}_scopeHistory.scope) AS {$p}_scope_name") - ->addGroupBy("{$p}_scope_name"); + ->addSelect("IDENTITY({$p}_scopeHistory.scope) AS {$p}_select") + ->addGroupBy("{$p}_select"); } public function applyOn(): string @@ -123,7 +123,7 @@ readonly class ReferrerScopeAggregator implements AggregatorInterface public function getQueryKeys($data): array { - return [self::PREFIX . '_scope_name']; + return [self::PREFIX . '_select']; } public function getTitle(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php index 883635a1e..bd65b555d 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php @@ -11,17 +11,27 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators; +use Chill\MainBundle\Entity\User\UserJobHistory; use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Repository\UserJobRepository; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverter; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; -use function in_array; final readonly class UserJobAggregator implements AggregatorInterface { - public function __construct(private UserJobRepository $jobRepository, private TranslatableStringHelper $translatableStringHelper) {} + private const PREFIX = 'acp_agg_user_job'; + + public function __construct( + private RollingDateConverter $rollingDateConverter, + private UserJobRepository $jobRepository, + private TranslatableStringHelper $translatableStringHelper + ) {} public function addRole(): ?string { @@ -30,12 +40,31 @@ final readonly class UserJobAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('acpuser', $qb->getAllAliases(), true)) { - $qb->leftJoin('acp.user', 'acpuser'); - } + $p = self::PREFIX; - $qb->addSelect('IDENTITY(acpuser.userJob) AS job_aggregator'); - $qb->addGroupBy('job_aggregator'); + $qb + ->leftJoin("acp.user", "{$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(): string @@ -45,11 +74,15 @@ final readonly class UserJobAggregator implements AggregatorInterface public function buildForm(FormBuilderInterface $builder) { - // no form + $builder + ->add('job_at', PickRollingDateType::class, [ + 'label' => 'export.acp.referrer_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) @@ -63,7 +96,9 @@ final readonly class UserJobAggregator implements AggregatorInterface return ''; } - $j = $this->jobRepository->find($value); + if (null === $j = $this->jobRepository->find($value)) { + return ''; + } return $this->translatableStringHelper->localize( $j->getLabel() @@ -73,11 +108,11 @@ final readonly class UserJobAggregator implements AggregatorInterface public function getQueryKeys($data): array { - return ['job_aggregator']; + return [self::PREFIX . '_select']; } public function getTitle(): string { - return 'Group by user job'; + return 'export.acp.referrer_job.Group by user job'; } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php index 3b692f782..77d1fdfcc 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregators; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractAggregatorTest; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\UserJobAggregator; @@ -39,7 +40,9 @@ final class UserJobAggregatorTest extends AbstractAggregatorTest public function getFormData(): array { return [ - [], + [ + 'job_at' => new RollingDate(RollingDate::T_TODAY) + ], ]; } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 0a8371f38..0dd982ae4 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -460,12 +460,14 @@ Filtered by person having an activity between %date_from% and %date_to% with rea ## accompanying course filters/aggr Filter by user scope: Filtrer les parcours par service du référent "Filtered by user main scope: only %scope%": "Filtré par service du référent: uniquement %scope%" - Group course by scope: Grouper les parcours par service Filter by user job: Filtrer les parcours par métier du référent "Filtered by user job: only %job%": "Filtré par métier du référent: uniquement %job%" -Group by user job: Grouper les parcours par métier du référent + +export.acp.referrer_job: + Group by user job: Grouper les parcours par métier du référent + Calc date: Date de calcul du métier du référent Filter by social issue: Filtrer les parcours par problématiques sociales Accepted socialissues: Problématiques sociales