[export] fix 4 job/scope aggregators in activity and aside activity

This commit is contained in:
Mathieu Jaumotte 2023-09-28 12:06:09 +02:00
parent 4460db1dc4
commit 3aa10927d7
6 changed files with 192 additions and 60 deletions

View File

@ -12,15 +12,26 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Export\Aggregator; namespace Chill\ActivityBundle\Export\Aggregator;
use Chill\ActivityBundle\Export\Declarations; 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\Repository\UserJobRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; 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 public function addRole(): ?string
{ {
@ -29,27 +40,48 @@ class ActivityUsersJobAggregator implements \Chill\MainBundle\Export\AggregatorI
public function alterQuery(QueryBuilder $qb, $data) public function alterQuery(QueryBuilder $qb, $data)
{ {
if (!in_array('actusers', $qb->getAllAliases(), true)) { $p = self::PREFIX;
$qb->leftJoin('activity.users', 'actusers');
}
$qb $qb
->addSelect('IDENTITY(actusers.userJob) AS activity_users_job_aggregator') ->leftJoin("activity.users", "{$p}_user")
->addGroupBy('activity_users_job_aggregator'); ->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; return Declarations::ACTIVITY;
} }
public function buildForm(FormBuilderInterface $builder) 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 public function getFormDefaultData(): array
{ {
return []; return ['job_at' => new RollingDate(RollingDate::T_TODAY)];
} }
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
@ -73,11 +105,11 @@ class ActivityUsersJobAggregator implements \Chill\MainBundle\Export\AggregatorI
public function getQueryKeys($data): array 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';
} }
} }

View File

@ -12,15 +12,26 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Export\Aggregator; namespace Chill\ActivityBundle\Export\Aggregator;
use Chill\ActivityBundle\Export\Declarations; 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\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; 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 public function addRole(): ?string
{ {
@ -29,27 +40,47 @@ class ActivityUsersScopeAggregator implements \Chill\MainBundle\Export\Aggregato
public function alterQuery(QueryBuilder $qb, $data) public function alterQuery(QueryBuilder $qb, $data)
{ {
if (!in_array('actusers', $qb->getAllAliases(), true)) { $p = self::PREFIX;
$qb->leftJoin('activity.users', 'actusers');
}
$qb $qb
->addSelect('IDENTITY(actusers.mainScope) AS activity_users_main_scope_aggregator') ->leftJoin("activity.users", "{$p}_user")
->addGroupBy('activity_users_main_scope_aggregator'); ->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; return Declarations::ACTIVITY;
} }
public function buildForm(FormBuilderInterface $builder) 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 public function getFormDefaultData(): array
{ {
return []; return ['scope_at' => new RollingDate(RollingDate::T_TODAY)];
} }
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
@ -73,11 +104,11 @@ class ActivityUsersScopeAggregator implements \Chill\MainBundle\Export\Aggregato
public function getQueryKeys($data): array 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';
} }
} }

View File

@ -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 users: Grouper les échanges par utilisateurs participants
Aggregate by activity type: Grouper les échanges par type Aggregate by activity type: Grouper les échanges par type
Aggregate by activity reason: Grouper les échanges par sujet 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 locationtype: Grouper les échanges par type de localisation
Group activity by date: Grouper les échanges par date Group activity by date: Grouper les échanges par date
@ -391,6 +387,15 @@ export:
by_location: by_location:
Activity Location: Localisation de l'échange Activity Location: Localisation de l'échange
Title: Grouper les échanges par 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: generic_doc:
filter: filter:

View File

@ -12,9 +12,14 @@ declare(strict_types=1);
namespace Chill\AsideActivityBundle\Export\Aggregator; namespace Chill\AsideActivityBundle\Export\Aggregator;
use Chill\AsideActivityBundle\Export\Declarations; use Chill\AsideActivityBundle\Export\Declarations;
use Chill\MainBundle\Entity\User\UserJobHistory;
use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Repository\UserJobRepositoryInterface; use Chill\MainBundle\Repository\UserJobRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -22,7 +27,13 @@ use function in_array;
class ByUserJobAggregator implements AggregatorInterface 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 public function addRole(): ?string
{ {
@ -31,27 +42,47 @@ class ByUserJobAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data) public function alterQuery(QueryBuilder $qb, $data)
{ {
if (!in_array('aside_user', $qb->getAllAliases(), true)) { $p = self::PREFIX;
$qb->leftJoin('aside.agent', 'aside_user');
}
$qb $qb
->addSelect('IDENTITY(aside_user.userJob) AS aside_activity_user_job_aggregator') ->leftJoin("aside.agent", "{$p}_user")
->addGroupBy('aside_activity_user_job_aggregator'); ->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; return Declarations::ASIDE_ACTIVITY_TYPE;
} }
public function buildForm(FormBuilderInterface $builder) 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 public function getFormDefaultData(): array
{ {
return []; return ['job_at' => new RollingDate(RollingDate::T_TODAY)];
} }
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
@ -75,11 +106,11 @@ class ByUserJobAggregator implements AggregatorInterface
public function getQueryKeys($data): array 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';
} }
} }

View File

@ -12,17 +12,26 @@ declare(strict_types=1);
namespace Chill\AsideActivityBundle\Export\Aggregator; namespace Chill\AsideActivityBundle\Export\Aggregator;
use Chill\AsideActivityBundle\Export\Declarations; use Chill\AsideActivityBundle\Export\Declarations;
use Chill\MainBundle\Entity\User\UserScopeHistory;
use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Repository\ScopeRepositoryInterface; use Chill\MainBundle\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class ByUserScopeAggregator implements AggregatorInterface 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 public function addRole(): ?string
{ {
@ -31,27 +40,47 @@ class ByUserScopeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data) public function alterQuery(QueryBuilder $qb, $data)
{ {
if (!in_array('aside_user', $qb->getAllAliases(), true)) { $p = self::PREFIX;
$qb->leftJoin('aside.agent', 'aside_user');
}
$qb $qb
->addSelect('IDENTITY(aside_user.mainScope) AS aside_activity_user_scope_aggregator') ->leftJoin("aside.agent", "{$p}_user")
->addGroupBy('aside_activity_user_scope_aggregator'); ->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; return Declarations::ASIDE_ACTIVITY_TYPE;
} }
public function buildForm(FormBuilderInterface $builder) 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 public function getFormDefaultData(): array
{ {
return []; return ['scope_at' => new RollingDate(RollingDate::T_TODAY)];
} }
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
@ -75,11 +104,11 @@ class ByUserScopeAggregator implements AggregatorInterface
public function getQueryKeys($data): array 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';
} }
} }

View File

@ -209,8 +209,12 @@ export:
aggregator: aggregator:
Group by aside activity type: Grouper les activités annexes par type d'activité Group by aside activity type: Grouper les activités annexes par type d'activité
Aside activity type: Type d'activité annexe Aside activity type: Type d'activité annexe
Aggregate by user job: Grouper les activités annexes par métier des utilisateurs by_user_job:
Aggregate by user scope: Grouper les activités annexes par service des utilisateurs 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 Aside activity location: Localisation des activités annexe
Group by aside activity location: Grouper les activités annexes par localisation Group by aside activity location: Grouper les activités annexes par localisation
Aside activity localisation: Localisation Aside activity localisation: Localisation