]> Raphaël G. Git Repositories - airbundle/commitdiff
Add findComplementBySessionId function
authorRaphaël Gertz <git@rapsys.eu>
Wed, 9 Dec 2020 20:38:13 +0000 (21:38 +0100)
committerRaphaël Gertz <git@rapsys.eu>
Wed, 9 Dec 2020 20:38:13 +0000 (21:38 +0100)
Repository/LocationRepository.php

index 7a29981d473c859393a79982dd46ad1b69c09dea..234d0e247eef5bee8113f10c887b6ab269a42cb2 100644 (file)
@@ -8,6 +8,25 @@ use Symfony\Component\Translation\TranslatorInterface;
  * LocationRepository
  */
 class LocationRepository extends \Doctrine\ORM\EntityRepository {
+       /**
+        * Find complementary locations by session id
+        *
+        * @param $id The session id
+        * @return array The other locations
+        */
+       public function findComplementBySessionId($id) {
+               //Fetch complement locations
+               $ret = $this->getEntityManager()
+                         ->createQuery('SELECT l.id, l.title FROM RapsysAirBundle:Session s LEFT JOIN RapsysAirBundle:Session s2 WITH s2.id != s.id AND s2.slot = s.slot AND s2.date = s.date LEFT JOIN RapsysAirBundle:Location l WITH l.id != s.location AND (l.id != s2.location OR s2.location IS NULL) WHERE s.id = :sid GROUP BY l.id ORDER BY l.id')
+                       ->setParameter('sid', $id)
+                       ->getArrayResult();
+
+               //Rekey array
+               $ret = array_column($ret, 'id', 'title');
+
+               return $ret;
+       }
+
        /**
         * Fetch translated location with session by date period
         *