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\User
; 
  11 class UserController 
extends DefaultController 
{ 
  13          * List all sessions for the user 
  15          * @desc Display all sessions for the user with an application or login form 
  17          * @param Request $request The request instance 
  18          * @param int $id The user id 
  20          * @return Response The rendered view 
  22         public function view(Request 
$request, $id) { 
  24                 $doctrine = $this->getDoctrine(); 
  27                 $user = $doctrine->getRepository(User
::class)->findOneById($id); 
  30                 $section = $user->getPseudonym(); 
  33                 $title = $section.' - '.$this->translator
->trans($this->config
['site']['title']); 
  38                 //Create application form for role_guest 
  39                 if ($this->isGranted('ROLE_GUEST')) { 
  40                         //Create ApplicationType form 
  41                         $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [ 
  43                                 'action' => $this->generateUrl('rapsys_air_application_add'), 
  44                                 //Set the form attribute 
  45                                 'attr' => [ 'class' => 'col' ], 
  47                                 'admin' => $this->isGranted('ROLE_ADMIN'), 
  48                                 //Set default user to current 
  49                                 'user' => $this->getUser()->getId(), 
  50                                 //Set default slot to evening 
  51                                 //XXX: default to Evening (3) 
  52                                 'slot' => $doctrine->getRepository(Slot
::class)->findOneById(3) 
  56                         $context['application'] = $application->createView(); 
  57                 //Create login form for anonymous 
  58                 } elseif (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { 
  59                         //Create ApplicationType form 
  60                         $login = $this->createForm('Rapsys\UserBundle\Form\LoginType', null, [ 
  62                                 'action' => $this->generateUrl('rapsys_user_login'), 
  63                                 //Set the form attribute 
  64                                 'attr' => [ 'class' => 'col' ] 
  68                         $context['login'] = $login->createView(); 
  72                 $period = new \
DatePeriod( 
  73                         //Start from first monday of week 
  74                         new \
DateTime('Monday this week'), 
  76                         new \
DateInterval('P1D'), 
  77                         //End with next sunday and 4 weeks 
  78                         new \
DateTime('Monday this week + 5 week') 
  82                 //TODO: highlight with current session route parameter 
  83                 $calendar = $doctrine->getRepository(Session
::class)->fetchUserCalendarByDatePeriod($this->translator
, $period, $id, $request->get('session')); 
  86                 return $this->render('@RapsysAir/user/view.html.twig', ['id' => $id, 'title' => $title, 'section' => $section, 'calendar' => $calendar]+
$context+
$this->context
);