mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-04 14:59:53 +00:00
FEATURE [repository] method added to repository to alter query using filters - not done
This commit is contained in:
parent
3cc56e7431
commit
f762f35386
@ -315,14 +315,14 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
$this->denyAccessUnlessGranted(ActivityVoter::SEE, $accompanyingPeriod);
|
$this->denyAccessUnlessGranted(ActivityVoter::SEE, $accompanyingPeriod);
|
||||||
|
|
||||||
|
$data = $form->getData();
|
||||||
|
|
||||||
$activities = $this->activityACLAwareRepository
|
$activities = $this->activityACLAwareRepository
|
||||||
->findByAccompanyingPeriod($accompanyingPeriod, ActivityVoter::SEE, 0, null, ['date' => 'DESC', 'id' => 'DESC']);
|
->findByAccompanyingPeriod($accompanyingPeriod, ActivityVoter::SEE, 0, null, ['date' => 'DESC', 'id' => 'DESC']);
|
||||||
|
|
||||||
$view = 'ChillActivityBundle:Activity:listAccompanyingCourse.html.twig';
|
$view = 'ChillActivityBundle:Activity:listAccompanyingCourse.html.twig';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->render(
|
return $this->render(
|
||||||
$view,
|
$view,
|
||||||
[
|
[
|
||||||
|
@ -12,10 +12,14 @@ declare(strict_types=1);
|
|||||||
namespace Chill\ActivityBundle\Repository;
|
namespace Chill\ActivityBundle\Repository;
|
||||||
|
|
||||||
use Chill\ActivityBundle\Entity\Activity;
|
use Chill\ActivityBundle\Entity\Activity;
|
||||||
|
use Chill\ActivityBundle\Entity\ActivityType;
|
||||||
|
use Chill\MainBundle\Entity\UserJob;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Activity|null find($id, $lockMode = null, $lockVersion = null)
|
* @method Activity|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
@ -25,9 +29,12 @@ use Doctrine\Persistence\ManagerRegistry;
|
|||||||
*/
|
*/
|
||||||
class ActivityRepository extends ServiceEntityRepository
|
class ActivityRepository extends ServiceEntityRepository
|
||||||
{
|
{
|
||||||
public function __construct(ManagerRegistry $registry)
|
private Security $security;
|
||||||
|
|
||||||
|
public function __construct(ManagerRegistry $registry, Security $security)
|
||||||
{
|
{
|
||||||
parent::__construct($registry, Activity::class);
|
parent::__construct($registry, Activity::class);
|
||||||
|
$this->security = $security;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,4 +104,47 @@ class ActivityRepository extends ServiceEntityRepository
|
|||||||
|
|
||||||
return $qb->getQuery()->getResult();
|
return $qb->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param QueryBuilder $qb
|
||||||
|
* @param array|UserJob $jobs
|
||||||
|
* @param array|ActivityType $types
|
||||||
|
* @param \DateTime $dateFrom
|
||||||
|
* @param \DateTime $dateTo
|
||||||
|
* @param bool $onlyMe
|
||||||
|
* @return 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'))
|
||||||
|
->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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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