mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-02 14:07:43 +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()) {
|
||||
$data = $form->getData();
|
||||
dump($data['types']->getValues());
|
||||
$activities = $this->activityACLAwareRepository
|
||||
->findByAccompanyingPeriod(
|
||||
$accompanyingPeriod,
|
||||
@ -326,23 +325,25 @@ final class ActivityController extends AbstractController
|
||||
$data['dateFrom'],
|
||||
$data['jobs']->getValues(),
|
||||
$data['types']->getValues(),
|
||||
$data['onlyMe'],
|
||||
null,
|
||||
['date' => 'DESC', 'id' => 'DESC']
|
||||
);
|
||||
} else {
|
||||
$activities = $this->activityACLAwareRepository
|
||||
->findByAccompanyingPeriod(
|
||||
$accompanyingPeriod,
|
||||
ActivityVoter::SEE,
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
[],
|
||||
[],
|
||||
false,
|
||||
null,
|
||||
['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';
|
||||
|
||||
|
@ -72,6 +72,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte
|
||||
?DateTime $after = null,
|
||||
?array $userJob = [],
|
||||
?array $activityTypes = [],
|
||||
bool $onlyMe = false,
|
||||
?int $limit = 1000,
|
||||
?array $orderBy = []
|
||||
): array {
|
||||
@ -86,7 +87,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte
|
||||
->getReachableCircles($user, $role, $center);
|
||||
|
||||
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
|
||||
|
@ -29,6 +29,7 @@ interface ActivityACLAwareRepositoryInterface
|
||||
?DateTime $after = null,
|
||||
?array $userJob = [],
|
||||
?array $activityTypes = [],
|
||||
bool $onlyMe = false,
|
||||
?int $limit = 1000,
|
||||
?array $orderBy = []
|
||||
): array;
|
||||
|
@ -52,6 +52,7 @@ class ActivityRepository extends ServiceEntityRepository
|
||||
?DateTime $after = null,
|
||||
?array $userJob = [],
|
||||
array $activityTypes = [],
|
||||
bool $onlyMe = false,
|
||||
?int $limit = 100,
|
||||
?int $offset = 0,
|
||||
array $orderBy = ['date' => 'desc']
|
||||
@ -80,31 +81,8 @@ class ActivityRepository extends ServiceEntityRepository
|
||||
)
|
||||
->setParameter('period', $period);
|
||||
|
||||
// Add filter parameters to query if any
|
||||
if ($before) {
|
||||
$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()
|
||||
}*/
|
||||
//Add filter queries
|
||||
$this->addQueryFilters($qb, $userJob, $activityTypes, $after, $before, $onlyMe);
|
||||
|
||||
foreach ($orderBy as $k => $dir) {
|
||||
$qb->addOrderBy('a.' . $k, $dir);
|
||||
@ -112,9 +90,6 @@ class ActivityRepository extends ServiceEntityRepository
|
||||
|
||||
$qb->setMaxResults($limit)->setFirstResult($offset);
|
||||
|
||||
dump($qb->getQuery());
|
||||
dump($qb->getQuery()->getResult());
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
@ -149,12 +124,15 @@ class ActivityRepository extends ServiceEntityRepository
|
||||
/**
|
||||
* @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
|
||||
private function addQueryFilters(QueryBuilder $qb, array $jobs, array $types, ?DateTime $dateFrom, ?DateTime $dateTo, bool $onlyMe): QueryBuilder
|
||||
{
|
||||
if (0 < count($jobs)) {
|
||||
$qb->join('a.user', 'u');
|
||||
$qb->andWhere($qb->expr()->in('u.job', ':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);
|
||||
}
|
||||
|
||||
@ -171,6 +149,12 @@ class ActivityRepository extends ServiceEntityRepository
|
||||
))
|
||||
->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) {
|
||||
|
@ -29,7 +29,8 @@
|
||||
|
||||
<h1>{{ 'Activity list'|trans }}</h1>
|
||||
|
||||
{# <div class="col-10">#}
|
||||
{# TODO: form error messages not displaying #}
|
||||
<p>{{ form_errors(form) }}</p>
|
||||
|
||||
{{ form_start(form) }}
|
||||
<div class="row">
|
||||
|
Loading…
x
Reference in New Issue
Block a user