3 namespace Rapsys\AirBundle\Repository
; 
   5 use Symfony\Component\Translation\TranslatorInterface
; 
  10 class LocationRepository 
extends \Doctrine\ORM\EntityRepository 
{ 
  12          * Find complementary locations by session id 
  14          * @param $id The session id 
  15          * @return array The other locations 
  17         public function findComplementBySessionId($id) { 
  18                 //Fetch complement locations 
  19                 $ret = $this->getEntityManager() 
  20                           ->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') 
  21                         ->setParameter('sid', $id) 
  25                 $ret = array_column($ret, 'id', 'title'); 
  31          * Fetch translated location with session by date period 
  33          * @param $translator The TranslatorInterface instance 
  34          * @param $period The date period 
  35          * @param $granted The session is granted 
  37         public function fetchTranslatedLocationByDatePeriod(TranslatorInterface 
$translator, $period, $granted = false) { 
  39                 $ret = $this->getEntityManager() 
  40                         ->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') 
  41                         ->setParameter('begin', $period->getStartDate()) 
  42                         ->setParameter('end', $period->getEndDate()) 
  46                 $ret = array_column($ret, 'title', 'id'); 
  49                 foreach($ret as $k => $v) { 
  50                         $ret[$k] = $translator->trans($v); 
  58          * Fetch translated user location with session by date period 
  60          * @param $translator The TranslatorInterface instance 
  61          * @param $period The date period 
  62          * @param $userId The user uid 
  64         public function fetchTranslatedUserLocationByDatePeriod(TranslatorInterface 
$translator, $period, $userId) { 
  66                 $ret = $this->getEntityManager() 
  67                           ->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') 
  68 #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 
  69                         ->setParameter('begin', $period->getStartDate()) 
  70                         ->setParameter('end', $period->getEndDate()) 
  71                         ->setParameter('uid', $userId) 
  75                 $ret = array_column($ret, 'title', 'id'); 
  78                 foreach($ret as $k => $v) { 
  79                         $ret[$k] = $translator->trans($v);