3 namespace Rapsys\AirBundle\Repository
;
5 use Symfony\Component\Translation\TranslatorInterface
;
10 class LocationRepository
extends \Doctrine\ORM\EntityRepository
{
12 * Fetch translated location with session by date period
14 * @param $translator The TranslatorInterface instance
15 * @param $period The date period
16 * @param $granted The session is granted
18 public function fetchTranslatedLocationByDatePeriod(TranslatorInterface
$translator, $period, $granted = false) {
20 $ret = $this->getEntityManager()
21 ->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')
22 ->setParameter('begin', $period->getStartDate())
23 ->setParameter('end', $period->getEndDate())
27 $ret = array_column($ret, 'title', 'id');
30 foreach($ret as $k => $v) {
31 $ret[$k] = $translator->trans($v);
39 * Fetch translated user location with session by date period
41 * @param $translator The TranslatorInterface instance
42 * @param $period The date period
43 * @param $userId The user uid
45 public function fetchTranslatedUserLocationByDatePeriod(TranslatorInterface
$translator, $period, $userId) {
47 $ret = $this->getEntityManager()
48 ->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')
49 #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
50 ->setParameter('begin', $period->getStartDate())
51 ->setParameter('end', $period->getEndDate())
52 ->setParameter('uid', $userId)
56 $ret = array_column($ret, 'title', 'id');
59 foreach($ret as $k => $v) {
60 $ret[$k] = $translator->trans($v);