[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

@@ -12,16 +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\ScopeRepository;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class CreatorScopeAggregator implements AggregatorInterface
{
public function __construct(private readonly ScopeRepository $scopeRepository, private readonly TranslatableStringHelper $translatableStringHelper) {}
private const PREFIX = 'acp_agg_creator_scope';
public function __construct(
private readonly RollingDateConverter $rollingDateConverter,
private readonly ScopeRepository $scopeRepository,
private readonly TranslatableStringHelper $translatableStringHelper
) {}
public function addRole(): ?string
{
@@ -30,12 +40,30 @@ class CreatorScopeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('actcreator', $qb->getAllAliases(), true)) {
$qb->leftJoin('activity.createdBy', 'actcreator');
}
$p = self::PREFIX;
$qb->addSelect('IDENTITY(actcreator.mainScope) AS creatorscope_aggregator');
$qb->addGroupBy('creatorscope_aggregator');
$qb
->leftJoin("activity.createdBy", "{$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(): string
@@ -45,11 +73,14 @@ class CreatorScopeAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder)
{
// no form
$builder->add('scope_at', PickRollingDateType::class, [
'label' => 'export.aggregator.activity.by_creator_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 CreatorScopeAggregator implements AggregatorInterface
public function getQueryKeys($data): array
{
return ['creatorscope_aggregator'];
return ['_select'];
}
public function getTitle(): string
{
return 'Group activity by creator scope';
return 'export.aggregator.activity.by_creator_scope.Group activity by creator scope';
}
}

View File

@@ -316,7 +316,6 @@ for week: Semaine
by year: Par année
in year: En
Group activity by creator: Grouper les échanges par créateur de l'échange
Group activity by creator scope: Grouper les échanges par service du créateur de l'échange
Group activity by linked thirdparties: Grouper les échanges par tiers impliqué
Accepted thirdparty: Tiers impliqué
Group activity by linked socialaction: Grouper les échanges par action liée
@@ -395,6 +394,9 @@ export:
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
by_creator_scope:
Group activity by creator scope: Grouper les échanges par service du créateur de l'échange
Calc date: Date de calcul du service du créateur de l'échange
generic_doc: