[export] fix 2 job/scope aggregators in activity and acp

This commit is contained in:
2023-09-28 12:27:53 +02:00
parent 3aa10927d7
commit bea21d45fc
4 changed files with 89 additions and 24 deletions

View File

@@ -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;
class CreatorJobAggregator implements AggregatorInterface
{
public function __construct(private readonly UserJobRepository $jobRepository, private readonly TranslatableStringHelper $translatableStringHelper) {}
private const PREFIX = 'acp_agg_creator_job';
public function __construct(
private readonly RollingDateConverter $rollingDateConverter,
private readonly UserJobRepository $jobRepository,
private readonly TranslatableStringHelper $translatableStringHelper
) {}
public function addRole(): ?string
{
@@ -30,12 +40,30 @@ class CreatorJobAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acp_creator', $qb->getAllAliases(), true)) {
$qb->leftJoin('acp.createdBy', 'acp_creator');
}
$p = self::PREFIX;
$qb->addSelect('IDENTITY(acp_creator.userJob) AS acp_creator_job_aggregator')
->addGroupBy('acp_creator_job_aggregator');
$qb
->leftJoin("acp.createdBy", "{$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 +73,14 @@ class CreatorJobAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder)
{
// No form needed
$builder->add('job_at', PickRollingDateType::class, [
'label' => 'export.aggregator.course.by_creator_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)
@@ -71,11 +102,11 @@ class CreatorJobAggregator implements AggregatorInterface
public function getQueryKeys($data): array
{
return ['acp_creator_job_aggregator'];
return [self::PREFIX . '_select'];
}
public function getTitle(): string
{
return 'Group by creator job';
return 'export.aggregator.course.by_creator_job.Group by creator job';
}
}

View File

@@ -573,7 +573,6 @@ Filter by creator: Filtrer les parcours par créateur
'Filtered by creator: only %creators%': 'Filtré par créateur: uniquement %creators%'
Filter by creator job: Filtrer les parcours par métier du créateur
'Filtered by creator job: only %jobs%': 'Filtré par métier du créateur: uniquement %jobs%'
Group by creator job: Grouper les parcours par métier du créateur
Filter actions without end date: Filtre les actions sans date de fin (ouvertes)
Filtered actions without end date: 'Filtré: uniquement les actions sans date de fin (ouvertes)'
@@ -1029,6 +1028,8 @@ export:
Number of actions: Nombre d'actions
by_creator_job:
Creator's job: Métier du créateur
Group by creator job: Grouper les parcours par métier du créateur
Calc date: Date de calcul du métier du créateur
by_user_working:
title: Grouper les parcours par intervenant
user: Intervenant