mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-01 12:33:49 +00:00
Resolve "Reorganise page 'Mes parcours'"
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,22 @@ use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
interface AccompanyingPeriodACLAwareRepositoryInterface
|
||||
{
|
||||
public const USER_IS_REFERRER = 0b0010; // 2 in decimal
|
||||
public const USER_IS_WORK_REFERRER = 0b0100; // 4 in decimal
|
||||
public const USER_IS_INTERVENING = 0b1000; // 8 in decimal
|
||||
|
||||
/**
|
||||
* Finds associations for a given user within a specific date range and step filters.
|
||||
*
|
||||
* @param \DateTimeImmutable|null $from the start date for filtering when intervention in accompanying period took place
|
||||
* @param \DateTimeImmutable|null $to the end date for filtering when intervention in accompanying period took place
|
||||
*
|
||||
* @return array the list of user associations matching the given criteria
|
||||
*/
|
||||
public function findByUserAssociation(User $user, array $steps, ?\DateTimeImmutable $from, ?\DateTimeImmutable $to, int $filter, ?int $start = 0, ?int $limit = 1000): array;
|
||||
|
||||
public function countByUserAssociation(User $user, array $steps, ?\DateTimeImmutable $from, ?\DateTimeImmutable $to, int $filter): int;
|
||||
|
||||
/**
|
||||
* @param array|UserJob[] $jobs
|
||||
* @param array|Scope[] $services
|
||||
|
@@ -62,6 +62,18 @@ final readonly class AccompanyingPeriodRepository implements ObjectRepository
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria): ?AccompanyingPeriod
|
||||
{
|
||||
return $this->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function getClassName()
|
||||
{
|
||||
return AccompanyingPeriod::class;
|
||||
}
|
||||
|
||||
// CUSTOM FIND BY METHODS
|
||||
|
||||
/**
|
||||
* @return array|AccompanyingPeriod[]
|
||||
*/
|
||||
@@ -87,16 +99,6 @@ final readonly class AccompanyingPeriodRepository implements ObjectRepository
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria): ?AccompanyingPeriod
|
||||
{
|
||||
return $this->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function getClassName()
|
||||
{
|
||||
return AccompanyingPeriod::class;
|
||||
}
|
||||
|
||||
private function buildQueryByRecentUserHistory(User $user, \DateTimeImmutable $since): QueryBuilder
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('a');
|
||||
|
Reference in New Issue
Block a user