]> Raphaël G. Git Repositories - airbundle/commitdiff
Add location repository with fetchTranslatedLocationByDatePeriod
authorRaphaël Gertz <git@rapsys.eu>
Mon, 19 Oct 2020 07:44:35 +0000 (09:44 +0200)
committerRaphaël Gertz <git@rapsys.eu>
Mon, 19 Oct 2020 07:44:35 +0000 (09:44 +0200)
Enable it in doctrine orm config

Repository/LocationRepository.php [new file with mode: 0644]
Resources/config/doctrine/Location.orm.yml

diff --git a/Repository/LocationRepository.php b/Repository/LocationRepository.php
new file mode 100644 (file)
index 0000000..80e0996
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace Rapsys\AirBundle\Repository;
+
+use Symfony\Component\Translation\TranslatorInterface;
+
+/**
+ * LocationRepository
+ */
+class LocationRepository extends \Doctrine\ORM\EntityRepository {
+       /**
+        * Fetch translated location with session by date period
+        *
+        * @param $translator The TranslatorInterface instance
+        * @param $period The date period
+        * @param $granted The session is granted
+        */
+       public function fetchTranslatedLocationByDatePeriod(TranslatorInterface $translator, $period, $granted = false) {
+               //Fetch sessions
+               $ret = $this->getEntityManager()
+                       ->createQuery('SELECT l.id, l.title FROM RapsysAirBundle:Session s JOIN RapsysAirBundle:Location l WHERE '.($granted?'s.application IS NOT NULL AND ':'').'l.id = s.location AND s.date BETWEEN :begin AND :end GROUP BY l.id ORDER BY l.id')
+                       ->setParameter('begin', $period->getStartDate())
+                       ->setParameter('end', $period->getEndDate())
+                       ->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;
+       }
+}
index 0b276fa48130917269aecf75d05f3b32451787d8..abed5ddf819b922b7ce82e8e17fa4d0599a301dd 100644 (file)
@@ -1,6 +1,6 @@
 Rapsys\AirBundle\Entity\Location:
     type: entity
-    #repositoryClass: Rapsys\AirBundle\Repository\LocationRepository
+    repositoryClass: Rapsys\AirBundle\Repository\LocationRepository
     table: locations
     id:
         id: