mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
rewrite task list action
This commit is contained in:
@@ -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 = []
|
||||
|
Reference in New Issue
Block a user