3 namespace Rapsys\AirBundle\Controller
; 
   5 use Symfony\Component\HttpFoundation\Request
; 
   7 use Rapsys\AirBundle\Entity\Slot
; 
   8 use Rapsys\AirBundle\Entity\Session
; 
   9 use Rapsys\AirBundle\Entity\Location
; 
  10 use Rapsys\AirBundle\Entity\User
; 
  12 class UserController 
extends DefaultController 
{ 
  14          * List all sessions for the user 
  16          * @desc Display all sessions for the user with an application or login form 
  18          * @param Request $request The request instance 
  19          * @param int $id The user id 
  21          * @return Response The rendered view 
  23         public function view(Request 
$request, $id) { 
  25                 $doctrine = $this->getDoctrine(); 
  28                 $user = $doctrine->getRepository(User
::class)->findOneById($id); 
  31                 $section = $user->getPseudonym(); 
  34                 $title = $section.' - '.$this->translator
->trans($this->config
['site']['title']); 
  39                 //Create application form for role_guest 
  40                 if ($this->isGranted('ROLE_GUEST')) { 
  41                         //Create ApplicationType form 
  42                         $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [ 
  44                                 'action' => $this->generateUrl('rapsys_air_application_add'), 
  45                                 //Set the form attribute 
  46                                 'attr' => [ 'class' => 'col' ], 
  48                                 'admin' => $this->isGranted('ROLE_ADMIN'), 
  49                                 //Set default user to current 
  50                                 'user' => $this->getUser()->getId(), 
  51                                 //Set default slot to evening 
  52                                 //XXX: default to Evening (3) 
  53                                 'slot' => $doctrine->getRepository(Slot
::class)->findOneById(3) 
  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                 //TODO: highlight with current session route parameter 
  84                 $calendar = $doctrine->getRepository(Session
::class)->fetchUserCalendarByDatePeriod($this->translator
, $period, $id, $request->get('session')); 
  87                 //XXX: we want to display all active locations anyway 
  88                 $locations = $doctrine->getRepository(Location
::class)->fetchTranslatedUserLocationByDatePeriod($this->translator
, $period, $id); 
  91                 return $this->render('@RapsysAir/user/view.html.twig', ['id' => $id, 'title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+
$context+
$this->context
);