[export] fix activity filters/aggregators + tests: 'at' based on activity date

This commit is contained in:
2023-10-03 15:24:41 +02:00
parent 6e48d036d7
commit fa3fc2c781
8 changed files with 31 additions and 96 deletions

View File

@@ -14,10 +14,7 @@ namespace Chill\ActivityBundle\Export\Aggregator;
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\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
@@ -28,7 +25,6 @@ class ActivityUsersJobAggregator implements AggregatorInterface
private const PREFIX = 'act_agg_user_job';
public function __construct(
private readonly RollingDateConverter $rollingDateConverter,
private readonly UserJobRepositoryInterface $userJobRepository,
private readonly TranslatableStringHelperInterface $translatableStringHelper
) {}
@@ -50,20 +46,17 @@ class ActivityUsersJobAggregator implements AggregatorInterface
Expr\Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
)
// job_at based on activity.date
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
$qb->expr()->lte("{$p}_history.startDate", "activity.date"),
$qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
$qb->expr()->gt("{$p}_history.endDate", "activity.date")
)
)
)
->addSelect("IDENTITY({$p}_history.job) AS {$p}_select")
->setParameter(
"{$p}_at",
$this->rollingDateConverter->convert($data['job_at'])
)
->addGroupBy("{$p}_select");
}
@@ -74,16 +67,11 @@ class ActivityUsersJobAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('job_at', PickRollingDateType::class, [
'label' => 'export.aggregator.activity.by_user_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)