From 5be05a787b5f5a2b660ceb9f68500f6c478f7b84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Sun, 29 Nov 2020 07:02:16 +0100 Subject: [PATCH] Add translated user location fetch by date period function --- Repository/LocationRepository.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Repository/LocationRepository.php b/Repository/LocationRepository.php index 80e0996..7a29981 100644 --- a/Repository/LocationRepository.php +++ b/Repository/LocationRepository.php @@ -34,4 +34,33 @@ class LocationRepository extends \Doctrine\ORM\EntityRepository { //Send result return $ret; } + + /** + * Fetch translated user location with session by date period + * + * @param $translator The TranslatorInterface instance + * @param $period The date period + * @param $userId The user uid + */ + public function fetchTranslatedUserLocationByDatePeriod(TranslatorInterface $translator, $period, $userId) { + //Fetch sessions + $ret = $this->getEntityManager() + ->createQuery('SELECT l.id, l.title FROM RapsysAirBundle:Application a JOIN RapsysAirBundle:Session s JOIN RapsysAirBundle:Location l WHERE a.user = :uid AND a.session = s.id AND s.date BETWEEN :begin AND :end AND s.location = l.id GROUP BY l.id ORDER BY l.id') +#SELECT l.id, l.title FROM RapsysAirBundle:Session s JOIN RapsysAirBundle:Application a JOIN RapsysAirBundle:Location l WHERE s.date BETWEEN :begin AND :end AND s.id = a.session AND l.id = s.location GROUP BY l.id ORDER BY l.id + ->setParameter('begin', $period->getStartDate()) + ->setParameter('end', $period->getEndDate()) + ->setParameter('uid', $userId) + ->getResult(); + + //Rekey array + $ret = array_column($ret, 'title', 'id'); + + //Filter array + foreach($ret as $k => $v) { + $ret[$k] = $translator->trans($v); + } + + //Send result + return $ret; + } } -- 2.41.1