mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-02 22:17:45 +00:00
FEATURE [filters][parameters] filter working, but still using deprecated method from ActivityRepository
This commit is contained in:
commit
033e1f9aa1
@ -316,7 +316,6 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
dump($data['types']->getValues());
|
|
||||||
$activities = $this->activityACLAwareRepository
|
$activities = $this->activityACLAwareRepository
|
||||||
->findByAccompanyingPeriod(
|
->findByAccompanyingPeriod(
|
||||||
$accompanyingPeriod,
|
$accompanyingPeriod,
|
||||||
@ -326,23 +325,25 @@ final class ActivityController extends AbstractController
|
|||||||
$data['dateFrom'],
|
$data['dateFrom'],
|
||||||
$data['jobs']->getValues(),
|
$data['jobs']->getValues(),
|
||||||
$data['types']->getValues(),
|
$data['types']->getValues(),
|
||||||
|
$data['onlyMe'],
|
||||||
|
null,
|
||||||
|
['date' => 'DESC', 'id' => 'DESC']
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$activities = $this->activityACLAwareRepository
|
||||||
|
->findByAccompanyingPeriod(
|
||||||
|
$accompanyingPeriod,
|
||||||
|
ActivityVoter::SEE,
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
false,
|
||||||
null,
|
null,
|
||||||
['date' => 'DESC', 'id' => 'DESC']
|
['date' => 'DESC', 'id' => 'DESC']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$activities = $this->activityACLAwareRepository
|
|
||||||
->findByAccompanyingPeriod(
|
|
||||||
$accompanyingPeriod,
|
|
||||||
ActivityVoter::SEE,
|
|
||||||
0,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
[],
|
|
||||||
[],
|
|
||||||
null,
|
|
||||||
['date' => 'DESC', 'id' => 'DESC']
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
$view = 'ChillActivityBundle:Activity:listAccompanyingCourse.html.twig';
|
$view = 'ChillActivityBundle:Activity:listAccompanyingCourse.html.twig';
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte
|
|||||||
?DateTime $after = null,
|
?DateTime $after = null,
|
||||||
?array $userJob = [],
|
?array $userJob = [],
|
||||||
?array $activityTypes = [],
|
?array $activityTypes = [],
|
||||||
|
bool $onlyMe = false,
|
||||||
?int $limit = 1000,
|
?int $limit = 1000,
|
||||||
?array $orderBy = []
|
?array $orderBy = []
|
||||||
): array {
|
): array {
|
||||||
@ -86,7 +87,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte
|
|||||||
->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, $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
|
||||||
|
@ -29,6 +29,7 @@ interface ActivityACLAwareRepositoryInterface
|
|||||||
?DateTime $after = null,
|
?DateTime $after = null,
|
||||||
?array $userJob = [],
|
?array $userJob = [],
|
||||||
?array $activityTypes = [],
|
?array $activityTypes = [],
|
||||||
|
bool $onlyMe = false,
|
||||||
?int $limit = 1000,
|
?int $limit = 1000,
|
||||||
?array $orderBy = []
|
?array $orderBy = []
|
||||||
): array;
|
): array;
|
||||||
|
@ -52,6 +52,7 @@ class ActivityRepository extends ServiceEntityRepository
|
|||||||
?DateTime $after = null,
|
?DateTime $after = null,
|
||||||
?array $userJob = [],
|
?array $userJob = [],
|
||||||
array $activityTypes = [],
|
array $activityTypes = [],
|
||||||
|
bool $onlyMe = false,
|
||||||
?int $limit = 100,
|
?int $limit = 100,
|
||||||
?int $offset = 0,
|
?int $offset = 0,
|
||||||
array $orderBy = ['date' => 'desc']
|
array $orderBy = ['date' => 'desc']
|
||||||
@ -80,31 +81,8 @@ class ActivityRepository extends ServiceEntityRepository
|
|||||||
)
|
)
|
||||||
->setParameter('period', $period);
|
->setParameter('period', $period);
|
||||||
|
|
||||||
// Add filter parameters to query if any
|
//Add filter queries
|
||||||
if ($before) {
|
$this->addQueryFilters($qb, $userJob, $activityTypes, $after, $before, $onlyMe);
|
||||||
$qb->andWhere(
|
|
||||||
$qb->expr()->lt('a.date', ':before')
|
|
||||||
);
|
|
||||||
$qb->setParameter('before', $before);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($after) {
|
|
||||||
$qb->andWhere(
|
|
||||||
$qb->expr()->lt('a.date', ':after')
|
|
||||||
);
|
|
||||||
$qb->setParameter('after', $after);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($activityTypes) > 0) {
|
|
||||||
$qb->andWhere(
|
|
||||||
$qb->expr()->in('a.activityType', ':activityTypes')
|
|
||||||
);
|
|
||||||
$qb->setParameter('activityTypes', $activityTypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*if (null !== $userJob) {
|
|
||||||
$qb->innerJoin()
|
|
||||||
}*/
|
|
||||||
|
|
||||||
foreach ($orderBy as $k => $dir) {
|
foreach ($orderBy as $k => $dir) {
|
||||||
$qb->addOrderBy('a.' . $k, $dir);
|
$qb->addOrderBy('a.' . $k, $dir);
|
||||||
@ -112,9 +90,6 @@ class ActivityRepository extends ServiceEntityRepository
|
|||||||
|
|
||||||
$qb->setMaxResults($limit)->setFirstResult($offset);
|
$qb->setMaxResults($limit)->setFirstResult($offset);
|
||||||
|
|
||||||
dump($qb->getQuery());
|
|
||||||
dump($qb->getQuery()->getResult());
|
|
||||||
|
|
||||||
return $qb->getQuery()->getResult();
|
return $qb->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,12 +124,15 @@ class ActivityRepository extends ServiceEntityRepository
|
|||||||
/**
|
/**
|
||||||
* @param array|UserJob $jobs
|
* @param array|UserJob $jobs
|
||||||
* @param array|ActivityType $types
|
* @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
|
private function addQueryFilters(QueryBuilder $qb, array $jobs, array $types, ?DateTime $dateFrom, ?DateTime $dateTo, bool $onlyMe): QueryBuilder
|
||||||
{
|
{
|
||||||
if (0 < count($jobs)) {
|
if (0 < count($jobs)) {
|
||||||
$qb->join('a.user', 'u');
|
//TODO check for jobs of all users involved
|
||||||
$qb->andWhere($qb->expr()->in('u.job', ':jobs'))
|
$qb->innerJoin('a.user', 'u');
|
||||||
|
$qb->andWhere($qb->expr()->in('u.userJob', ':jobs'))
|
||||||
->setParameter('jobs', $jobs);
|
->setParameter('jobs', $jobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +149,12 @@ class ActivityRepository extends ServiceEntityRepository
|
|||||||
))
|
))
|
||||||
->setParameter('date_from', $dateFrom)
|
->setParameter('date_from', $dateFrom)
|
||||||
->setParameter('date_to', $dateTo);
|
->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) {
|
if (true === $onlyMe) {
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
|
|
||||||
<h1>{{ 'Activity list'|trans }}</h1>
|
<h1>{{ 'Activity list'|trans }}</h1>
|
||||||
|
|
||||||
{# <div class="col-10">#}
|
{# TODO: form error messages not displaying #}
|
||||||
|
<p>{{ form_errors(form) }}</p>
|
||||||
|
|
||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user