mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[export] fix acp ReferrerScopeAggregator query + unit test
TO CHECK: logic in alterQuery. calc_date is same for 2 histories ?
This commit is contained in:
parent
3f4a42adb2
commit
9db0011b2e
@ -72,6 +72,7 @@ final readonly class JobAggregator implements AggregatorInterface
|
||||
{
|
||||
$builder->add('job_at', PickRollingDateType::class, [
|
||||
'label' => 'export.calendar.agent_job.Calc date',
|
||||
'required' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,7 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
||||
{
|
||||
$builder->add('scope_at', PickRollingDateType::class, [
|
||||
'label' => 'export.calendar.agent_scope.Calc date',
|
||||
'required' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
|
@ -85,6 +85,7 @@ class JobFilter implements FilterInterface
|
||||
])
|
||||
->add('job_at', PickRollingDateType::class, [
|
||||
'label' => 'export.calendar.agent_job.Calc date',
|
||||
'required' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
|
@ -80,6 +80,7 @@ class ScopeFilter implements FilterInterface
|
||||
])
|
||||
->add('scope_at', PickRollingDateType::class, [
|
||||
'label' => 'export.calendar.agent_scope.Calc date',
|
||||
'required' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
|
||||
|
||||
use Chill\MainBundle\Entity\User\UserScopeHistory;
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
|
||||
@ -18,15 +19,20 @@ use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\Query\Expr;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use LogicException;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class ReferrerScopeAggregator implements AggregatorInterface
|
||||
readonly class ReferrerScopeAggregator implements AggregatorInterface
|
||||
{
|
||||
private const SCOPE_KEY = 'acp_agg_refscope_user_history_ref_scope_name';
|
||||
private const PREFIX = 'acp_agg_referrer_scope';
|
||||
|
||||
public function __construct(private readonly ScopeRepositoryInterface $scopeRepository, private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly RollingDateConverterInterface $rollingDateConverter) {}
|
||||
public function __construct(
|
||||
private ScopeRepositoryInterface $scopeRepository,
|
||||
private TranslatableStringHelperInterface $translatableStringHelper,
|
||||
private RollingDateConverterInterface $rollingDateConverter
|
||||
) {}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
@ -35,48 +41,59 @@ class ReferrerScopeAggregator implements AggregatorInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$userHistory = 'acp_agg_refscope_user_history';
|
||||
$ref = 'acp_agg_refscope_user_history_ref';
|
||||
$scopeName = self::SCOPE_KEY;
|
||||
$dateCalc = 'acp_agg_refscope_user_history_date_calc';
|
||||
$p = self::PREFIX;
|
||||
|
||||
$qb
|
||||
->leftJoin('acp.userHistories', $userHistory)
|
||||
->leftJoin($userHistory . '.user', $ref)
|
||||
->leftJoin("acp.userHistories", "{$p}_userHistory")
|
||||
->leftJoin("{$p}_userHistory.user", "{$p}_user")
|
||||
->leftJoin(
|
||||
UserScopeHistory::class,
|
||||
"{$p}_scopeHistory",
|
||||
Expr\Join::WITH,
|
||||
$qb->expr()->eq("{$p}_scopeHistory.user", "{$p}_user")
|
||||
)
|
||||
->andWhere(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull($userHistory),
|
||||
$qb->expr()->isNull("{$p}_userHistory"),
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte($userHistory . '.startDate', ':' . $dateCalc),
|
||||
$qb->expr()->lte("{$p}_userHistory.startDate", ":{$p}_date_calc"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull($userHistory . '.endDate'),
|
||||
$qb->expr()->gt($userHistory . '.endDate', ':' . $dateCalc)
|
||||
$qb->expr()->isNull("{$p}_userHistory.endDate"),
|
||||
$qb->expr()->gt("{$p}_userHistory.endDate", ":{$p}_date_calc")
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
->andWhere(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte("{$p}_scopeHistory.startDate", ":{$p}_date_calc"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull("{$p}_scopeHistory.endDate"),
|
||||
$qb->expr()->gt("{$p}_scopeHistory.endDate", ":{$p}_date_calc")
|
||||
)
|
||||
)
|
||||
)
|
||||
->setParameter(
|
||||
$dateCalc,
|
||||
"{$p}_date_calc",
|
||||
$this->rollingDateConverter->convert($data['date_calc'])
|
||||
);
|
||||
|
||||
// add groups
|
||||
$qb
|
||||
->addSelect('IDENTITY(' . $ref . '.mainScope) AS ' . $scopeName)
|
||||
->addGroupBy($scopeName);
|
||||
)
|
||||
->addSelect("IDENTITY({$p}_scopeHistory.scope) AS {$p}_scope_name")
|
||||
->addGroupBy("{$p}_scope_name");
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
public function applyOn(): string
|
||||
{
|
||||
return Declarations::ACP_TYPE;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('date_calc', PickRollingDateType::class, [
|
||||
$builder
|
||||
->add('date_calc', PickRollingDateType::class, [
|
||||
'label' => 'export.aggregator.course.by_user_scope.Computation date for referrer',
|
||||
'required' => true,
|
||||
]);
|
||||
])
|
||||
;
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
@ -104,12 +121,12 @@ class ReferrerScopeAggregator implements AggregatorInterface
|
||||
};
|
||||
}
|
||||
|
||||
public function getQueryKeys($data)
|
||||
public function getQueryKeys($data): array
|
||||
{
|
||||
return [self::SCOPE_KEY];
|
||||
return [self::PREFIX . '_scope_name'];
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'export.aggregator.course.by_user_scope.Group course by referrer\'s scope';
|
||||
}
|
||||
|
@ -71,7 +71,6 @@ final class ReferrerScopeAggregatorTest extends AbstractAggregatorTest
|
||||
$em->createQueryBuilder()
|
||||
->select('count(acp.id)')
|
||||
->from(AccompanyingPeriod::class, 'acp')
|
||||
->join('acp.scopes', 'acpscope'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user