rewrite task list action

This commit is contained in:
2021-10-30 00:41:28 +02:00
parent c63b1015e1
commit e0cb5a88bd
4 changed files with 123 additions and 203 deletions

View File

@@ -106,6 +106,31 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository
->getQuery()->getSingleScalarResult();
}
public function countByAllViewable(
?string $pattern = null,
?array $flags = []
): int {
$qb = $this->buildBaseQuery($pattern, $flags);
return $this
->addACLGlobal($qb)
->select('COUNT(t)')
->getQuery()->getSingleScalarResult();
}
public function findByAllViewable(
?string $pattern = null,
?array $flags = [],
?int $start = 0,
?int $limit = 50,
?array $orderBy = []
): array {
$qb = $this->buildBaseQuery($pattern, $flags);
$qb = $this->addACLGlobal($qb);
return $this->getResult($qb, $start, $limit, $orderBy);
}
public function buildQueryByCourse(
AccompanyingPeriod $course,
?string $pattern = null,
@@ -175,6 +200,50 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository
->setParameter('scopes', $scopes);
}
private function addACLGlobal(
QueryBuilder $qb
): QueryBuilder {
$allowedCenters = $this->authorizationHelper
->getReachableCenters($this->security->getUser(), TaskVoter::SHOW);
if ([] === $allowedCenters) {
$qb
->andWhere($qb->expr()->lt('t.id', ':falseid'))
->setParameter('falseid', -1);
}
$qb->leftJoin('t.person', 'person')
->leftJoin('t.course', 'course')
->leftJoin('course.participations', 'participation')
->leftJoin('participation.person', 'person_p')
;
$qb->distinct(true);
$k = 0;
$orX = $qb->expr()->orX();
foreach ($allowedCenters as $center) {
$allowedScopes = $this->authorizationHelper->getReachableScopes($this->security->getUser(),
TaskVoter::SHOW, $center);
$and = $qb->expr()->andX(
$qb->expr()->orX(
$qb->expr()->eq('person.center', ':center_'.$k),
$qb->expr()->eq('person_p.center', ':center_'.$k)
),
$qb->expr()->in('t.circle', ':scopes_'.$k)
);
$qb
->setParameter('center_'.$k, $center)
->setParameter('scopes_'.$k, $allowedScopes);
$orX->add($and);
$k++;
}
$qb->andWhere($orX);
return $qb;
}
public function buildBaseQuery (
?string $pattern = null,
?array $flags = []