mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 18:43:49 +00:00
[export] fix calendar filters/aggregators + tests: 'at' based on calendar date
This commit is contained in:
@@ -14,13 +14,10 @@ namespace Chill\CalendarBundle\Export\Aggregator;
|
||||
use Chill\CalendarBundle\Export\Declarations;
|
||||
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\RollingDateConverterInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Closure;
|
||||
use Doctrine\ORM\Query\Expr;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
@@ -29,7 +26,6 @@ final readonly class JobAggregator implements AggregatorInterface
|
||||
private const PREFIX = 'cal_agg_job';
|
||||
|
||||
public function __construct(
|
||||
private RollingDateConverterInterface $rollingDateConverter,
|
||||
private UserJobRepository $jobRepository,
|
||||
private TranslatableStringHelper $translatableStringHelper
|
||||
) {}
|
||||
@@ -44,22 +40,24 @@ final readonly class JobAggregator implements AggregatorInterface
|
||||
$p = self::PREFIX;
|
||||
|
||||
$qb
|
||||
->leftJoin(
|
||||
'cal.mainUser',
|
||||
"{$p}_user"
|
||||
)
|
||||
->leftJoin('cal.mainUser', "{$p}_user")
|
||||
->leftJoin(
|
||||
UserJobHistory::class,
|
||||
"{$p}_history",
|
||||
Expr\Join::WITH,
|
||||
Join::WITH,
|
||||
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
|
||||
)
|
||||
->andWhere("{$p}_history.startDate <= :{$p}_at AND ({$p}_history.endDate IS NULL OR {$p}_history.endDate > :{$p}_at)")
|
||||
->addSelect("IDENTITY({$p}_history.job) AS {$p}_select")
|
||||
->setParameter(
|
||||
"{$p}_at",
|
||||
$this->rollingDateConverter->convert($data['job_at'])
|
||||
// job_at based on cal.startDate
|
||||
->andWhere(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte("{$p}_history.startDate", "cal.startDate"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull("{$p}_history.endDate"),
|
||||
$qb->expr()->gt("{$p}_history.endDate", "cal.startDate")
|
||||
)
|
||||
)
|
||||
)
|
||||
->addSelect("IDENTITY({$p}_history.job) AS {$p}_select")
|
||||
->addGroupBy("{$p}_select");
|
||||
}
|
||||
|
||||
@@ -70,15 +68,11 @@ final readonly class JobAggregator implements AggregatorInterface
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('job_at', PickRollingDateType::class, [
|
||||
'label' => 'export.calendar.agent_job.Calc date',
|
||||
'required' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return ['job_at' => new RollingDate(RollingDate::T_TODAY)];
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
@@ -109,6 +103,6 @@ final readonly class JobAggregator implements AggregatorInterface
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Group calendars by agent job';
|
||||
return 'export.aggregator.calendar.agent_job.Group calendars by agent job';
|
||||
}
|
||||
}
|
||||
|
@@ -14,24 +14,18 @@ namespace Chill\CalendarBundle\Export\Aggregator;
|
||||
use Chill\CalendarBundle\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\RollingDateConverterInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Closure;
|
||||
use Doctrine\ORM\Query\Expr;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\Exp;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use function in_array;
|
||||
|
||||
final readonly class ScopeAggregator implements AggregatorInterface
|
||||
{
|
||||
private const PREFIX = "cal_agg_scope";
|
||||
|
||||
public function __construct(
|
||||
private RollingDateConverterInterface $rollingDateConverter,
|
||||
private ScopeRepository $scopeRepository,
|
||||
private TranslatableStringHelper $translatableStringHelper
|
||||
) {}
|
||||
@@ -46,22 +40,24 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
||||
$p = self::PREFIX;
|
||||
|
||||
$qb
|
||||
->leftJoin(
|
||||
"cal.mainUser",
|
||||
"{$p}_user"
|
||||
)
|
||||
->leftJoin("cal.mainUser", "{$p}_user")
|
||||
->leftJoin(
|
||||
UserScopeHistory::class,
|
||||
"{$p}_history",
|
||||
Expr\Join::WITH,
|
||||
Join::WITH,
|
||||
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
|
||||
)
|
||||
->andWhere("{$p}_history.startDate <= :{$p}_at AND ({$p}_history.endDate IS NULL OR {$p}_history.endDate > :{$p}_at)")
|
||||
->addSelect("IDENTITY({$p}_history.scope) AS {$p}_select")
|
||||
->setParameter(
|
||||
"{$p}_at",
|
||||
$this->rollingDateConverter->convert($data['scope_at'])
|
||||
// scope_at based on cal.startDate
|
||||
->andWhere(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte("{$p}_history.startDate", "cal.startDate"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull("{$p}_history.endDate"),
|
||||
$qb->expr()->gt("{$p}_history.endDate", "cal.startDate")
|
||||
)
|
||||
)
|
||||
)
|
||||
->addSelect("IDENTITY({$p}_history.scope) AS {$p}_select")
|
||||
->addGroupBy("{$p}_select");
|
||||
}
|
||||
|
||||
@@ -72,14 +68,11 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('scope_at', PickRollingDateType::class, [
|
||||
'label' => 'export.calendar.agent_scope.Calc date',
|
||||
'required' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return ['scope_at' => new RollingDate(RollingDate::T_TODAY)];
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data): Closure
|
||||
@@ -110,6 +103,6 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Group calendars by agent scope';
|
||||
return 'export.aggregator.calendar.agent_scope.Group calendars by agent scope';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user