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          * Find translated location title sorted 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 findTranslatedSortedByPeriod(TranslatorInterface 
$translator, $period, $userId = null) { 
  39                 $ret = $this->getEntityManager() 
  42 FROM RapsysAirBundle:Location l 
  43 LEFT JOIN RapsysAirBundle:Session s WITH s.location = l.id AND s.date BETWEEN :begin AND :end 
  44 LEFT JOIN RapsysAirBundle:Application a WITH a.id = s.application'.(!empty($userId)?' AND a.user = :uid':'').' 
  46 ORDER BY '.(!empty($userId)?'COUNT(a.id) DESC, ':'').'COUNT(s.id) DESC, l.id' 
  48                         ->setParameter('begin', $period->getStartDate()) 
  49                         ->setParameter('end', $period->getEndDate()); 
  51                 //Set optional user id 
  52                 if (!empty($userId)) { 
  53                         $ret->setParameter('uid', $userId); 
  57                 $ret = $ret->getResult(); 
  60                 $ret = array_column($ret, 'title', 'id'); 
  63                 foreach($ret as $k => $v) { 
  64                         $ret[$k] = $translator->trans($v); 
  72          * Fetch translated location title with session by date period 
  74          * @param $translator The TranslatorInterface instance 
  75          * @param $period The date period 
  76          * @param $granted The session is granted 
  79         public function fetchTranslatedLocationByDatePeriod(TranslatorInterface 
$translator, $period, $granted = false) { 
  81                 $ret = $this->getEntityManager() 
  82                         ->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') 
  83                         ->setParameter('begin', $period->getStartDate()) 
  84                         ->setParameter('end', $period->getEndDate()) 
  88                 $ret = array_column($ret, 'title', 'id'); 
  91                 foreach($ret as $k => $v) { 
  92                         $ret[$k] = $translator->trans($v); 
 100          * Fetch translated location title with user session by date period 
 102          * @param $translator The TranslatorInterface instance 
 103          * @param $period The date period 
 104          * @param $userId The user uid 
 107         public function fetchTranslatedUserLocationByDatePeriod(TranslatorInterface 
$translator, $period, $userId) { 
 109                 $ret = $this->getEntityManager() 
 110                           ->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') 
 111 #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 
 112                         ->setParameter('begin', $period->getStartDate()) 
 113                         ->setParameter('end', $period->getEndDate()) 
 114                         ->setParameter('uid', $userId) 
 118                 $ret = array_column($ret, 'title', 'id'); 
 121                 foreach($ret as $k => $v) { 
 122                         $ret[$k] = $translator->trans($v);