Resolve "Reorganise page 'Mes parcours'"

This commit is contained in:
2025-05-21 16:13:43 +00:00
committed by Julien Fastré
parent dc44c46667
commit 44a8ddeba4
6 changed files with 244 additions and 32 deletions

View File

@@ -365,4 +365,90 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
return $qb;
}
public function findByUserAssociation(User $user, array $steps, ?\DateTimeImmutable $from, ?\DateTimeImmutable $to, int $filter, ?int $start = 0, ?int $limit = 1000): array
{
$qb = $this->buildQueryByUserAssociation($user, $steps, $from, $to, $filter);
$qb->addOrderBy('acp.openingDate', 'DESC');
if (null !== $start) {
$qb->setFirstResult($start);
}
if (null !== $limit) {
$qb->setMaxResults($limit);
}
return $qb->getQuery()->getResult();
}
public function countByUserAssociation(User $user, array $steps, ?\DateTimeImmutable $from, ?\DateTimeImmutable $to, int $filter): int
{
$qb = $this->buildQueryByUserAssociation($user, $steps, $from, $to, $filter);
$qb->select('COUNT(DISTINCT acp.id)');
return $qb->getQuery()->getSingleScalarResult();
}
public function buildQueryByUserAssociation(User $user, array $steps, ?\DateTimeImmutable $from, ?\DateTimeImmutable $to, int $filter): QueryBuilder
{
$qb = $this->accompanyingPeriodRepository->createQueryBuilder('acp');
// Create an andX expression to hold the user association conditions
$whereUserAssociation = $qb->expr()->andX();
if (($filter & self::USER_IS_REFERRER) > 0) {
$whereUserAssociation->add($qb->expr()->eq('acp.user', ':user'));
}
if (($filter & self::USER_IS_WORK_REFERRER) > 0) {
$whereUserAssociation->add(
$qb->expr()->exists(
'SELECT 1
FROM '.AccompanyingPeriod\AccompanyingPeriodWork::class.' subw
JOIN subw.referrersHistory subw_ref_history
WHERE subw.id = acpw.id
AND subw_ref_history.user = :user
AND subw_ref_history.endDate IS NULL'
)
);
$qb->innerJoin('acp.works', 'acpw');
}
if (($filter & self::USER_IS_INTERVENING) > 0) {
$expr = 'SELECT 1
FROM '.AccompanyingPeriod\AccompanyingPeriodInfo::class.' info
WHERE info.accompanyingPeriod = acp
AND info.user = :user';
if (null !== $from) {
$expr .= ' AND info.infoDate >= :from';
$qb->setParameter('from', $from);
}
if (null !== $to) {
$expr .= ' AND info.infoDate <= :to';
$qb->setParameter('to', $to);
}
$whereUserAssociation->add(
$qb->expr()->exists($expr)
);
}
// Apply the compound condition to the query builder
$qb->andWhere($whereUserAssociation);
// Apply the steps condition
$qb->andWhere($qb->expr()->in('acp.step', ':steps'));
// Set the remaining parameters
$qb->setParameter('user', $user)
->setParameter('steps', $steps);
return $qb;
}
}