]> Raphaƫl G. Git Repositories - airbundle/blob - Repository/LocationRepository.php
80e099605112431951deb320875645a59bc31c0a
[airbundle] / Repository / LocationRepository.php
1 <?php
2
3 namespace Rapsys\AirBundle\Repository;
4
5 use Symfony\Component\Translation\TranslatorInterface;
6
7 /**
8 * LocationRepository
9 */
10 class LocationRepository extends \Doctrine\ORM\EntityRepository {
11 /**
12 * Fetch translated location with session by date period
13 *
14 * @param $translator The TranslatorInterface instance
15 * @param $period The date period
16 * @param $granted The session is granted
17 */
18 public function fetchTranslatedLocationByDatePeriod(TranslatorInterface $translator, $period, $granted = false) {
19 //Fetch sessions
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())
24 ->getResult();
25
26 //Rekey array
27 $ret = array_column($ret, 'title', 'id');
28
29 //Filter array
30 foreach($ret as $k => $v) {
31 $ret[$k] = $translator->trans($v);
32 }
33
34 //Send result
35 return $ret;
36 }
37 }