mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-02 22:17:45 +00:00
FIX changes to repository: using ACLAware instead of deprecated method
This commit is contained in:
parent
033e1f9aa1
commit
0b7651f519
@ -64,31 +64,31 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte
|
|||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findByAccompanyingPeriod(
|
/* public function findByAccompanyingPeriod(
|
||||||
AccompanyingPeriod $period,
|
AccompanyingPeriod $period,
|
||||||
string $role,
|
string $role,
|
||||||
?int $start = 0,
|
?int $start = 0,
|
||||||
?DateTime $before = null,
|
?DateTime $before = null,
|
||||||
?DateTime $after = null,
|
?DateTime $after = null,
|
||||||
?array $userJob = [],
|
?array $userJob = [],
|
||||||
?array $activityTypes = [],
|
?array $activityTypes = [],
|
||||||
bool $onlyMe = false,
|
bool $onlyMe = false,
|
||||||
?int $limit = 1000,
|
?int $limit = 1000,
|
||||||
?array $orderBy = []
|
?array $orderBy = []
|
||||||
): array {
|
): array {
|
||||||
$user = $this->security->getUser();
|
$user = $this->security->getUser();
|
||||||
$center = $this->centerResolverDispatcher->resolveCenter($period);
|
$center = $this->centerResolverDispatcher->resolveCenter($period);
|
||||||
|
|
||||||
if (0 === count($orderBy)) {
|
if (0 === count($orderBy)) {
|
||||||
$orderBy = ['date' => 'DESC'];
|
$orderBy = ['date' => 'DESC'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$scopes = $this->authorizationHelper
|
$scopes = $this->authorizationHelper
|
||||||
->getReachableCircles($user, $role, $center);
|
->getReachableCircles($user, $role, $center);
|
||||||
|
|
||||||
return $this->em->getRepository(Activity::class)
|
return $this->em->getRepository(Activity::class)
|
||||||
->findByAccompanyingPeriod($period, $scopes, true, $before, $after, $userJob, $activityTypes, $onlyMe, $limit, $start, $orderBy);
|
->findByAccompanyingPeriod($period, $scopes, true, $before, $after, $userJob, $activityTypes, $onlyMe, $limit, $start, $orderBy);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public function findByAccompanyingPeriodSimplified(AccompanyingPeriod $period, ?int $limit = 1000): array
|
public function findByAccompanyingPeriodSimplified(AccompanyingPeriod $period, ?int $limit = 1000): array
|
||||||
{
|
{
|
||||||
@ -210,6 +210,62 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Activity[]
|
||||||
|
*/
|
||||||
|
private function findByAccompanyingPeriod(
|
||||||
|
AccompanyingPeriod $period,
|
||||||
|
string $role,
|
||||||
|
?int $start = 0,
|
||||||
|
?DateTime $before = null,
|
||||||
|
?DateTime $after = null,
|
||||||
|
?array $userJob = [],
|
||||||
|
?array $activityTypes = [],
|
||||||
|
bool $onlyMe = false,
|
||||||
|
?int $limit = 100,
|
||||||
|
?int $offset = 0,
|
||||||
|
?array $orderBy = ['date' => 'desc']
|
||||||
|
): array {
|
||||||
|
$qb = $this->createQueryBuilder('a');
|
||||||
|
$qb->select('a');
|
||||||
|
|
||||||
|
$user = $this->security->getUser();
|
||||||
|
$center = $this->centerResolverDispatcher->resolveCenter($period);
|
||||||
|
|
||||||
|
if (0 === count($orderBy)) {
|
||||||
|
$orderBy = ['date' => 'DESC'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$scopes = $this->authorizationHelper
|
||||||
|
->getReachableCircles($user, $role, $center);
|
||||||
|
|
||||||
|
$qb
|
||||||
|
->where(
|
||||||
|
$qb->expr()->orX(
|
||||||
|
$qb->expr()->in('a.scope', ':scopes'),
|
||||||
|
$qb->expr()->isNull('a.scope')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setParameter('scopes', $scopes);
|
||||||
|
|
||||||
|
$qb
|
||||||
|
->andWhere(
|
||||||
|
$qb->expr()->eq('a.accompanyingPeriod', ':period')
|
||||||
|
)
|
||||||
|
->setParameter('period', $period);
|
||||||
|
|
||||||
|
//Add filter queries
|
||||||
|
$this->repository->addQueryFilters($qb, $userJob, $activityTypes, $after, $before, $onlyMe);
|
||||||
|
|
||||||
|
foreach ($orderBy as $k => $dir) {
|
||||||
|
$qb->addOrderBy('a.' . $k, $dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb->setMaxResults($limit)->setFirstResult($offset);
|
||||||
|
|
||||||
|
return $qb->getQuery()->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
private function getFromClauseCenter(array $args): string
|
private function getFromClauseCenter(array $args): string
|
||||||
{
|
{
|
||||||
$metadataActivity = $this->em->getClassMetadata(Activity::class);
|
$metadataActivity = $this->em->getClassMetadata(Activity::class);
|
||||||
|
@ -31,6 +31,7 @@ interface ActivityACLAwareRepositoryInterface
|
|||||||
?array $activityTypes = [],
|
?array $activityTypes = [],
|
||||||
bool $onlyMe = false,
|
bool $onlyMe = false,
|
||||||
?int $limit = 1000,
|
?int $limit = 1000,
|
||||||
|
?int $offset = 0,
|
||||||
?array $orderBy = []
|
?array $orderBy = []
|
||||||
): array;
|
): array;
|
||||||
|
|
||||||
|
@ -39,6 +39,52 @@ class ActivityRepository extends ServiceEntityRepository
|
|||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array|UserJob $jobs
|
||||||
|
* @param array|ActivityType $types
|
||||||
|
* @param DateTime $dateFrom
|
||||||
|
* @param DateTime $dateTo
|
||||||
|
*/
|
||||||
|
public function addQueryFilters(QueryBuilder $qb, array $jobs, array $types, ?DateTime $dateFrom, ?DateTime $dateTo, bool $onlyMe): QueryBuilder
|
||||||
|
{
|
||||||
|
if (0 < count($jobs)) {
|
||||||
|
//TODO check for jobs of all users involved
|
||||||
|
$qb->innerJoin('a.user', 'u');
|
||||||
|
$qb->andWhere($qb->expr()->in('u.userJob', ':jobs'))
|
||||||
|
->setParameter('jobs', $jobs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 < count($types)) {
|
||||||
|
$qb->andWhere($qb->expr()->in('a.activityType', ':types'))
|
||||||
|
->setParameter('types', $types);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $dateFrom && null !== $dateTo) {
|
||||||
|
$qb->andWhere($qb->expr()->between(
|
||||||
|
'a.date',
|
||||||
|
':date_from',
|
||||||
|
':date_to'
|
||||||
|
))
|
||||||
|
->setParameter('date_from', $dateFrom)
|
||||||
|
->setParameter('date_to', $dateTo);
|
||||||
|
} elseif (null !== $dateFrom && null === $dateTo) {
|
||||||
|
$qb->andWhere($qb->expr()->gt('a.date', ':date_from'))
|
||||||
|
->setParameter('date_from', $dateFrom);
|
||||||
|
} elseif (null === $dateFrom && null !== $dateTo) {
|
||||||
|
$qb->andWhere($qb->expr()->lt('a.date', ':date_to'))
|
||||||
|
->setParameter('date_to', $dateTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true === $onlyMe) {
|
||||||
|
$currentUser = $this->security->getUser();
|
||||||
|
|
||||||
|
$qb->andWhere($qb->expr()->eq('a.user', ':currentUser'))
|
||||||
|
->setParameter('currentUser', $currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $qb;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use @see{ActivityACLAwareRepositoryInterface::findByAccompanyingPeriod}
|
* @deprecated use @see{ActivityACLAwareRepositoryInterface::findByAccompanyingPeriod}
|
||||||
*
|
*
|
||||||
@ -120,50 +166,4 @@ class ActivityRepository extends ServiceEntityRepository
|
|||||||
|
|
||||||
return $qb->getQuery()->getResult();
|
return $qb->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array|UserJob $jobs
|
|
||||||
* @param array|ActivityType $types
|
|
||||||
* @param DateTime $dateFrom
|
|
||||||
* @param DateTime $dateTo
|
|
||||||
*/
|
|
||||||
private function addQueryFilters(QueryBuilder $qb, array $jobs, array $types, ?DateTime $dateFrom, ?DateTime $dateTo, bool $onlyMe): QueryBuilder
|
|
||||||
{
|
|
||||||
if (0 < count($jobs)) {
|
|
||||||
//TODO check for jobs of all users involved
|
|
||||||
$qb->innerJoin('a.user', 'u');
|
|
||||||
$qb->andWhere($qb->expr()->in('u.userJob', ':jobs'))
|
|
||||||
->setParameter('jobs', $jobs);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 < count($types)) {
|
|
||||||
$qb->andWhere($qb->expr()->in('a.activityType', ':types'))
|
|
||||||
->setParameter('types', $types);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null !== $dateFrom && null !== $dateTo) {
|
|
||||||
$qb->andWhere($qb->expr()->between(
|
|
||||||
'a.date',
|
|
||||||
':date_from',
|
|
||||||
':date_to'
|
|
||||||
))
|
|
||||||
->setParameter('date_from', $dateFrom)
|
|
||||||
->setParameter('date_to', $dateTo);
|
|
||||||
} elseif (null !== $dateFrom && null === $dateTo) {
|
|
||||||
$qb->andWhere($qb->expr()->gt('a.date', ':date_from'))
|
|
||||||
->setParameter('date_from', $dateFrom);
|
|
||||||
} elseif (null === $dateFrom && null !== $dateTo) {
|
|
||||||
$qb->andWhere($qb->expr()->lt('a.date', ':date_to'))
|
|
||||||
->setParameter('date_to', $dateTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (true === $onlyMe) {
|
|
||||||
$currentUser = $this->security->getUser();
|
|
||||||
|
|
||||||
$qb->andWhere($qb->expr()->eq('a.user', ':currentUser'))
|
|
||||||
->setParameter('currentUser', $currentUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $qb;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user