3 namespace Rapsys\AirBundle\Controller
; 
   5 use Symfony\Component\HttpFoundation\Request
; 
   6 use Rapsys\AirBundle\Entity\Slot
; 
   7 use Rapsys\AirBundle\Entity\Session
; 
   8 use Rapsys\AirBundle\Entity\Location
; 
  10 class LocationController 
extends DefaultController 
{ 
  12          * List all sessions for the location 
  14          * @desc Display all sessions for the location with an application or login form 
  16          * @param Request $request The request instance 
  17          * @param int $id The location id 
  19          * @return Response The rendered view 
  21         public function view(Request 
$request, $id) { 
  23                 $doctrine = $this->getDoctrine(); 
  26                 $location = $doctrine->getRepository(Location
::class)->findOneById($id); 
  29                 $section = $this->translator
->trans($location); 
  32                 $title = $section.' - '.$this->translator
->trans($this->config
['site']['title']); 
  37                 //Create application form for role_guest 
  38                 if ($this->isGranted('ROLE_GUEST')) { 
  39                         //Create ApplicationType form 
  40                         $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [ 
  42                                 'action' => $this->generateUrl('rapsys_air_application_add'), 
  43                                 //Set the form attribute 
  44                                 'attr' => [ 'class' => 'col' ], 
  46                                 'admin' => $this->isGranted('ROLE_ADMIN'), 
  47                                 //Set default user to current 
  48                                 'user' => $this->getUser()->getId(), 
  49                                 //Set default slot to evening 
  50                                 //XXX: default to Evening (3) 
  51                                 'slot' => $doctrine->getRepository(Slot
::class)->findOneById(3), 
  52                                 //Set default location to current one 
  53                                 'location' => $location 
  57                         $context['application'] = $application->createView(); 
  58                 //Create login form for anonymous 
  59                 } elseif (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { 
  60                         //Create ApplicationType form 
  61                         $login = $this->createForm('Rapsys\UserBundle\Form\LoginType', null, [ 
  63                                 'action' => $this->generateUrl('rapsys_user_login'), 
  64                                 //Set the form attribute 
  65                                 'attr' => [ 'class' => 'col' ] 
  69                         $context['login'] = $login->createView(); 
  73                 $period = new \
DatePeriod( 
  74                         //Start from first monday of week 
  75                         new \
DateTime('Monday this week'), 
  77                         new \
DateInterval('P1D'), 
  78                         //End with next sunday and 4 weeks 
  79                         new \
DateTime('Monday this week + 5 week') 
  83                 $calendar = $doctrine->getRepository(Session
::class)->fetchCalendarByDatePeriod($this->translator
, $period, $id, $request->get('session'), !$this->isGranted('IS_AUTHENTICATED_REMEMBERED')); 
  86                 //XXX: we want to display all active locations anyway 
  87                 $locations = $doctrine->getRepository(Location
::class)->fetchTranslatedLocationByDatePeriod($this->translator
, $period/*, !$this->isGranted('IS_AUTHENTICATED_REMEMBERED')*/); 
  90                 return $this->render('@RapsysAir/location/view.html.twig', ['id' => $id, 'title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+
$context+
$this->context
);