fix methods for accompanying period repository acl aware

* add method to interface
* delegate ACL to another method
This commit is contained in:
2022-03-21 14:54:01 +01:00
parent 293efc03b4
commit ac9e55e2fc
5 changed files with 39 additions and 15 deletions

View File

@@ -42,28 +42,32 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
$this->centerResolverDispatcher = $centerResolverDispatcher;
}
public function buildQueryByUser(?User $user)
public function buildQueryOpenedAccompanyingCourseByUser(?User $user)
{
$qb = $this->accompanyingPeriodRepository->createQueryBuilder('ap');
$qb->where($qb->expr()->eq('ap.user', ':user'))
->andWhere(
$qb->expr()->eq('ap.step', ':confirmed'),
$qb->expr()->eq('ap.confidential', 'false')
$qb->expr()->neq('ap.step', ':draft'),
$qb->expr()->orX(
$qb->expr()->isNull('ap.closingDate'),
$qb->expr()->gt('ap.closingDate', ':now')
)
)
->setParameter('user', $user)
->setParameter('confirmed', AccompanyingPeriod::STEP_CONFIRMED);
->setParameter('now', new \DateTime('now'))
->setParameter('draft', AccompanyingPeriod::STEP_DRAFT);
return $qb;
}
public function countByUserConfirmed(?User $user)
public function countByUserOpenedAccompanyingPeriod(?User $user): int
{
if (null === $user) {
return 0;
}
return $this->buildQueryByUser($user)
return $this->buildQueryOpenedAccompanyingCourseByUser($user)
->select('COUNT(ap)')
->getQuery()
->getSingleScalarResult();
@@ -124,13 +128,20 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
/**
* @return array|AccompanyingPeriod[]
*/
public function findByUserConfirmed(?User $user, int $limit, int $offset): array
public function findByUserOpenedAccompanyingPeriod(?User $user, array $orderBy = [], int $limit = 0, int $offset = 50): array
{
if (null === $user) {
return [];
}
$qb = $this->buildQueryByUser($user);
$qb = $this->buildQueryOpenedAccompanyingCourseByUser($user);
$qb->setFirstResult($offset)
->setMaxResults($limit);
foreach ($orderBy as $field => $direction) {
$qb->addOrderBy('ap.'.$field, $direction);
}
return $qb->getQuery()->getResult();
}