mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[export] fix acp userJob Filter query + unit test (partial)
This commit is contained in:
parent
e738bf0f5e
commit
f225a83a3e
@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||
|
||||
use Chill\MainBundle\Entity\User\UserJobHistory;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||
@ -22,19 +23,16 @@ use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class UserJobFilter implements FilterInterface
|
||||
{
|
||||
private const A = 'acp_ujob_filter_uhistory';
|
||||
private const PREFIX = 'acp_filter_user_job';
|
||||
|
||||
private const AU = 'acp_ujob_filter_uhistory_user';
|
||||
|
||||
private const P = 'acp_ujob_filter_date';
|
||||
|
||||
private const PJ = 'acp_ujob_filter_job';
|
||||
|
||||
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper, private readonly UserJobRepositoryInterface $userJobRepository, private readonly RollingDateConverterInterface $rollingDateConverter) {}
|
||||
public function __construct(
|
||||
private readonly TranslatableStringHelper $translatableStringHelper,
|
||||
private readonly UserJobRepositoryInterface $userJobRepository,
|
||||
private readonly RollingDateConverterInterface $rollingDateConverter
|
||||
) {}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
@ -43,26 +41,42 @@ class UserJobFilter implements FilterInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$p = self::PREFIX;
|
||||
|
||||
$qb
|
||||
->join('acp.userHistories', self::A)
|
||||
->leftJoin("acp.userHistories", "{$p}_userHistory")
|
||||
->leftJoin("{$p}_userHistory.user", "{$p}_user")
|
||||
->leftJoin(
|
||||
UserJobHistory::class,
|
||||
"{$p}_jobHistory",
|
||||
$qb->expr()->eq("{$p}_jobHistory", "{$p}_user")
|
||||
)
|
||||
->andWhere(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte(self::A . '.startDate', ':' . self::P),
|
||||
$qb->expr()->lte("{$p}_userHistory.startDate", ":{$p}_date"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull(self::A . '.endDate'),
|
||||
$qb->expr()->gt(self::A . '.endDate', ':' . self::P)
|
||||
$qb->expr()->isNull("{$p}_userHistory" . ".endDate"),
|
||||
$qb->expr()->gt("{$p}_userHistory.endDate", ":{$p}_date")
|
||||
)
|
||||
)
|
||||
)
|
||||
->setParameter(
|
||||
self::P,
|
||||
$this->rollingDateConverter->convert($data['date_calc'])
|
||||
)
|
||||
->join(self::A . '.user', self::AU)
|
||||
->andWhere(
|
||||
$qb->expr()->in(self::AU . '.userJob', ':' . self::PJ)
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte("{$p}_jobHistory.startDate", ":{$p}_date"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull("{$p}_jobHistory" . ".endDate"),
|
||||
$qb->expr()->gt("{$p}_jobHistory.endDate", ":{$p}_date")
|
||||
)
|
||||
)
|
||||
)
|
||||
->setParameter(self::PJ, $data['jobs']);
|
||||
->andWhere(
|
||||
$qb->expr()->in("{$p}_jobHistory.job", ":{$p}_job")
|
||||
)
|
||||
->setParameters([
|
||||
["{$p}_job", $data["jobs"]],
|
||||
["{$p}_date", $this->rollingDateConverter->convert($data["date_calc"])]
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
@ -106,7 +120,7 @@ class UserJobFilter implements FilterInterface
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
public function getTitle():string
|
||||
{
|
||||
return 'export.filter.course.by_user_job.Filter by user job';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user