From 178f44fd2da0f2439657128071a05b245e0d85b0 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Fri, 10 Jan 2025 14:55:14 +0000 Subject: [PATCH] add methods to get travel info --- src/Repository/CaseItineraryRepository.php | 38 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Repository/CaseItineraryRepository.php b/src/Repository/CaseItineraryRepository.php index d2a7b00..aaee4e2 100644 --- a/src/Repository/CaseItineraryRepository.php +++ b/src/Repository/CaseItineraryRepository.php @@ -6,6 +6,8 @@ use App\Entity\CaseItinerary; use App\Entity\MemberCase; use App\Entity\User; use App\Entity\UserCase; +use DateTime; +use DateTimeZone; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; @@ -21,8 +23,6 @@ class CaseItineraryRepository extends ServiceEntityRepository 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') @@ -49,6 +49,40 @@ class CaseItineraryRepository extends ServiceEntityRepository return $query->getQuery()->getResult(); } + public function getYTDTravel(User $user): ?array + { + $startDate = new DateTime('now', new DateTimeZone($_ENV['COMPANY_TIMEZONE'])); + + $query = $this->createQueryBuilder('ci') + ->leftJoin(UserCase::class, 'uc', 'WITH', 'uc.memberCase = ci.memberCase') + ->andWhere('uc.user = :user') + ->setParameter('user', $user->getId()->toBinary()) + ->andWhere('ci.date >= :from') + ->setParameter('from', $startDate->format('Y-01-01')) + ->orderBy('ci.date', 'DESC') + ->addOrderBy('ci.arrival', 'DESC') + ; + + return $query->getQuery()->getResult(); + } + + public function getTravelLast30Days(User $user): ?array + { + $startDate = new DateTime('now', new DateTimeZone($_ENV['COMPANY_TIMEZONE'])); + + $query = $this->createQueryBuilder('ci') + ->leftJoin(UserCase::class, 'uc', 'WITH', 'uc.memberCase = ci.memberCase') + ->andWhere('uc.user = :user') + ->setParameter('user', $user->getId()->toBinary()) + ->andWhere('ci.date >= :from') + ->setParameter('from', $startDate->modify('-30 days')->format('Y-m-d')) + ->orderBy('ci.date', 'DESC') + ->addOrderBy('ci.arrival', 'DESC') + ; + + return $query->getQuery()->getResult(); + } + // /** // * @return CaseLocation[] Returns an array of CaseLocation objects // */