From 781935821b1e0a9d6f467c51420534eeb85ee30f Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Wed, 1 Jan 2025 06:01:18 +0000 Subject: [PATCH] add getRecentTravel method --- src/Repository/CaseItineraryRepository.php | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Repository/CaseItineraryRepository.php b/src/Repository/CaseItineraryRepository.php index 3d042f5..d2a7b00 100644 --- a/src/Repository/CaseItineraryRepository.php +++ b/src/Repository/CaseItineraryRepository.php @@ -3,6 +3,9 @@ namespace App\Repository; use App\Entity\CaseItinerary; +use App\Entity\MemberCase; +use App\Entity\User; +use App\Entity\UserCase; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; @@ -16,6 +19,36 @@ class CaseItineraryRepository extends ServiceEntityRepository parent::__construct($registry, CaseItinerary::class); } + public function getRecentTravel(User $user, ?array $params = null): ?array + { + //dd($params); + + $query = $this->createQueryBuilder('ci') + ->leftJoin(UserCase::class, 'uc', 'WITH', 'uc.memberCase = ci.memberCase') + ->andWhere('uc.user = :user') + ->setParameter('user', $user->getId()->toBinary()) + ; + + if (isset($params['case']) && is_a($params['case'], MemberCase::class)) { + $query->andWhere('ci.memberCase = :case')->setParameter('case', $params['case']->getId()->toBinary()); + } + + if (isset($params['from']) && is_a($params['from'], \DateTime::class)) { + $query->andWhere('ci.date >= :from')->setParameter('from', $params['from']->format('Y-m-d')); + } + + if (isset($params['to']) && is_a($params['to'], \DateTime::class)) { + $query->andWhere('ci.date <= :to')->setParameter('to', $params['to']->format('Y-m-d')); + } + + $query->orderBy('ci.date', 'DESC') + ->addOrderBy('ci.arrival', 'DESC'); + + //dd($query->getQuery()); + + return $query->getQuery()->getResult(); + } + // /** // * @return CaseLocation[] Returns an array of CaseLocation objects // */