]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Controller/SessionController.php
Add return types
[airbundle] / Controller / SessionController.php
index a8cdfd9cc8d1eebd54c93a4b4ff43a1fce1a2896..26ceb94a268ad5424e056a00a521a49e8aeea2e1 100644 (file)
@@ -3,6 +3,7 @@
 namespace Rapsys\AirBundle\Controller;
 
 use Symfony\Component\HttpFoundation\Request;
 namespace Rapsys\AirBundle\Controller;
 
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Routing\RequestContext;
 use Symfony\Component\Routing\Exception\MethodNotAllowedException;
 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
 use Symfony\Component\Routing\RequestContext;
 use Symfony\Component\Routing\Exception\MethodNotAllowedException;
 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
@@ -24,7 +25,7 @@ class SessionController extends DefaultController {
         *
         * @throws \RuntimeException When user has not at least guest role
         */
         *
         * @throws \RuntimeException When user has not at least guest role
         */
-       public function edit(Request $request, $id) {
+       public function edit(Request $request, $id): Response {
                //Prevent non-guest to access here
                $this->denyAccessUnlessGranted('ROLE_GUEST', null, $this->translator->trans('Unable to access this page without role %role%!', ['%role%' => $this->translator->trans('Guest')]));
 
                //Prevent non-guest to access here
                $this->denyAccessUnlessGranted('ROLE_GUEST', null, $this->translator->trans('Unable to access this page without role %role%!', ['%role%' => $this->translator->trans('Guest')]));
 
@@ -37,7 +38,7 @@ class SessionController extends DefaultController {
                $doctrine = $this->getDoctrine();
 
                //Fetch session
                $doctrine = $this->getDoctrine();
 
                //Fetch session
-               $session = $doctrine->getRepository(Session::class)->fetchOneById($id);
+               $session = $doctrine->getRepository(Session::class)->fetchOneById($id, $request->getLocale());
 
                //Check if
                if (
 
                //Check if
                if (
@@ -55,8 +56,8 @@ class SessionController extends DefaultController {
                //Set now
                $now = new \DateTime('now');
 
                //Set now
                $now = new \DateTime('now');
 
-               //Create SessionEditType form
-               $form = $this->createForm('Rapsys\AirBundle\Form\SessionEditType', null, [
+               //Create SessionType form
+               $form = $this->createForm('Rapsys\AirBundle\Form\SessionType', null, [
                        //Set the action
                        'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]),
                        //Set the form attribute
                        //Set the action
                        'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]),
                        //Set the form attribute
@@ -70,13 +71,15 @@ class SessionController extends DefaultController {
                        //Set length
                        'length' => $session['length'],
                        //Set raincancel
                        //Set length
                        'length' => $session['length'],
                        //Set raincancel
-                       'raincancel' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['rainfall'] >= 2,
+                       'raincancel' => ($this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id']) && $session['rainfall'] >= 2,
                        //Set cancel
                        'cancel' => $this->isGranted('ROLE_ADMIN') || in_array($this->getUser()->getId(), explode("\n", $session['sau_id'])),
                        //Set modify
                        'modify' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_REGULAR'),
                        //Set move
                        'move' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_SENIOR'),
                        //Set cancel
                        'cancel' => $this->isGranted('ROLE_ADMIN') || in_array($this->getUser()->getId(), explode("\n", $session['sau_id'])),
                        //Set modify
                        'modify' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_REGULAR'),
                        //Set move
                        'move' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_SENIOR'),
+                       //Set attribute
+                       'attribute' => $this->isGranted('ROLE_ADMIN') && $session['locked'] === null,
                        //Set session
                        'session' => $session['id']
                ]);
                        //Set session
                        'session' => $session['id']
                ]);
@@ -127,49 +130,53 @@ class SessionController extends DefaultController {
                //Set datetime
                $datetime = new \DateTime('now');
 
                //Set datetime
                $datetime = new \DateTime('now');
 
-               //With raincancel
-               if ($form->has('raincancel') && $form->get('raincancel')->isClicked()) {
-                       //Check rainfall
-                       if ($this->isGranted('ROLE_ADMIN') || $session->getRainfall() >= 2) {
-                               //Check that application is attributed
-                               if (!empty($application = $session->getApplication())) {
-                                       //Get application
-                                       $application = $doctrine->getRepository(Application::class)->findOneBySessionUser($session, $application->getUser());
+               //Set canceled time at start minus one day
+               $canceled = (clone $session->getStart())->sub(new \DateInterval('P1D'));
+
+               //Set action
+               $action = [
+                       'raincancel' => $form->has('raincancel') && $form->get('raincancel')->isClicked(),
+                       'modify' => $form->has('modify') && $form->get('modify')->isClicked(),
+                       'move' => $form->has('move') && $form->get('move')->isClicked(),
+                       'cancel' => $form->has('cancel') && $form->get('cancel')->isClicked(),
+                       'forcecancel' => $form->has('forcecancel') && $form->get('forcecancel')->isClicked(),
+                       'attribute' => $form->has('attribute') && $form->get('attribute')->isClicked(),
+                       'autoattribute' => $form->has('autoattribute') && $form->get('autoattribute')->isClicked(),
+                       'lock' => $form->has('lock') && $form->get('lock')->isClicked(),
+               ];
 
 
-                                       //Set canceled time at start minus one day
-                                       $canceled = (clone $session->getStart())->sub(new \DateInterval('P1D'));
+               //With raincancel and application and (rainfall or admin)
+               if ($action['raincancel'] && ($application = $session->getApplication()) && ($session->getRainfall() >= 2 || $this->isGranted('ROLE_ADMIN'))) {
+                       //Cancel application at start minus one day
+                       $application->setCanceled($canceled);
 
 
-                                       //Cancel application
-                                       $application->setCanceled($canceled);
+                       //Update time
+                       $application->setUpdated($datetime);
 
 
-                                       //Update time
-                                       $application->setUpdated($datetime);
+                       //Insufficient rainfall
+                       //XXX: is admin
+                       if ($session->getRainfall() < 2) {
+                               //Set score
+                               //XXX: magic cheat score 42
+                               $application->setScore(42);
+                       }
 
 
-                                       //Queue application save
-                                       $manager->persist($application);
+                       //Queue application save
+                       $manager->persist($application);
 
 
-                                       //Add notice in flash message
-                                       $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
-                                       //Update time
-                                       $session->setUpdated($datetime);
+                       //Add notice in flash message
+                       $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
 
 
-                                       //Queue session save
-                                       $manager->persist($session);
+                       //Update time
+                       $session->setUpdated($datetime);
 
 
-                                       //Add notice in flash message
-                                       $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
-                               //Not attributed
-                               } else {
-                                       //Add notice in flash message
-                                       $this->addFlash('warning', $this->translator->trans('Session %id% not updated', ['%id%' => $id]));
-                               }
-                       //Not enough rainfall
-                       } else {
-                               //Add notice in flash message
-                               $this->addFlash('warning', $this->translator->trans('Session %id% not updated', ['%id%' => $id]));
-                       }
+                       //Queue session save
+                       $manager->persist($session);
+
+                       //Add notice in flash message
+                       $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
                //With modify
                //With modify
-               } elseif ($form->has('modify') && $form->get('modify')->isClicked()) {
+               } elseif ($action['modify']) {
                        //Set begin
                        $session->setBegin($data['begin']);
 
                        //Set begin
                        $session->setBegin($data['begin']);
 
@@ -185,7 +192,7 @@ class SessionController extends DefaultController {
                        //Add notice in flash message
                        $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
                //With move
                        //Add notice in flash message
                        $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
                //With move
-               } elseif ($form->has('move') && $form->get('move')->isClicked()) {
+               } elseif ($action['move']) {
                        //Set location
                        $session->setLocation($doctrine->getRepository(Location::class)->findOneById($data['location']));
 
                        //Set location
                        $session->setLocation($doctrine->getRepository(Location::class)->findOneById($data['location']));
 
@@ -197,8 +204,8 @@ class SessionController extends DefaultController {
 
                        //Add notice in flash message
                        $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
 
                        //Add notice in flash message
                        $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
-               //With cancel
-               } elseif ($form->has('cancel') && $form->get('cancel')->isClicked()) {
+               //With cancel or forcecancel
+               } elseif ($action['cancel'] || $action['forcecancel']) {
                        //Get application
                        $application = $doctrine->getRepository(Application::class)->findOneBySessionUser($session, $user);
 
                        //Get application
                        $application = $doctrine->getRepository(Application::class)->findOneBySessionUser($session, $user);
 
@@ -207,8 +214,13 @@ class SessionController extends DefaultController {
                                //Cancel application
                                $application->setCanceled($datetime);
 
                                //Cancel application
                                $application->setCanceled($datetime);
 
-                               //Check if application is session application
-                               if ($session->getApplication() == $application) {
+                               //Check if application is session application and (canceled 24h before start or forcecancel (as admin))
+                               #if ($session->getApplication() == $application && ($datetime < $canceled || $action['forcecancel'])) {
+                               if ($session->getApplication() == $application && $action['forcecancel']) {
+                                       //Set score
+                                       //XXX: magic cheat score 42
+                                       $application->setScore(42);
+
                                        //Unattribute session
                                        $session->setApplication(null);
 
                                        //Unattribute session
                                        $session->setApplication(null);
 
@@ -236,7 +248,7 @@ class SessionController extends DefaultController {
                        //Add notice in flash message
                        $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
                //With attribute
                        //Add notice in flash message
                        $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
                //With attribute
-               } elseif ($form->has('attribute') && $form->get('attribute')->isClicked()) {
+               } elseif ($action['attribute']) {
                        //Get application
                        $application = $doctrine->getRepository(Application::class)->findOneBySessionUser($session, $user);
 
                        //Get application
                        $application = $doctrine->getRepository(Application::class)->findOneBySessionUser($session, $user);
 
@@ -271,7 +283,7 @@ class SessionController extends DefaultController {
                        //Add notice in flash message
                        $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
                //With autoattribute
                        //Add notice in flash message
                        $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
                //With autoattribute
-               } elseif ($form->has('autoattribute') && $form->get('autoattribute')->isClicked()) {
+               } elseif ($action['autoattribute']) {
                        //Get best application
                        //XXX: best application may not issue result while grace time or bad behaviour
                        if (!empty($application = $doctrine->getRepository(Session::class)->findBestApplicationById($id))) {
                        //Get best application
                        //XXX: best application may not issue result while grace time or bad behaviour
                        if (!empty($application = $doctrine->getRepository(Session::class)->findBestApplicationById($id))) {
@@ -285,14 +297,14 @@ class SessionController extends DefaultController {
                                $manager->persist($session);
 
                                //Add notice in flash message
                                $manager->persist($session);
 
                                //Add notice in flash message
-                               $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
+                               $this->addFlash('notice', $this->translator->trans('Session %id% auto attributed', ['%id%' => $id]));
                        //No application
                        } else {
                        //No application
                        } else {
-                               //Add notice in flash message
-                               $this->addFlash('warning', $this->translator->trans('Session %id% not updated', ['%id%' => $id]));
+                               //Add warning in flash message
+                               $this->addFlash('warning', $this->translator->trans('Session %id% not auto attributed', ['%id%' => $id]));
                        }
                //With lock
                        }
                //With lock
-               } elseif ($form->has('lock') && $form->get('lock')->isClicked()) {
+               } elseif ($action['lock']) {
                        //Already locked
                        if ($session->getLocked() !== null) {
                                //Set uncanceled
                        //Already locked
                        if ($session->getLocked() !== null) {
                                //Set uncanceled
@@ -302,25 +314,11 @@ class SessionController extends DefaultController {
                                $session->setLocked(null);
                        //Not locked
                        } else {
                                $session->setLocked(null);
                        //Not locked
                        } else {
-                               //Set canceled time at start minus one day
-                               $canceled = (clone $session->getStart())->sub(new \DateInterval('P1D'));
-
-                               //Unattribute session
-                               $session->setApplication(null);
-
-                               //Lock session
-                               $session->setLocked($datetime);
-                       }
-
-                       //Get applications
-                       $applications = $doctrine->getRepository(Application::class)->findBySession($session);
-
-                       //Not empty
-                       if (!empty($applications)) {
-                               //Iterate on each applications
-                               foreach($applications as $application) {
-                                       //Cancel application
-                                       $application->setCanceled($canceled);
+                               //Get application
+                               if ($application = $session->getApplication()) {
+                                       //Set score
+                                       //XXX: magic cheat score 42
+                                       $application->setScore(42);
 
                                        //Update time
                                        $application->setUpdated($datetime);
 
                                        //Update time
                                        $application->setUpdated($datetime);
@@ -331,8 +329,35 @@ class SessionController extends DefaultController {
                                        //Add notice in flash message
                                        $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
                                }
                                        //Add notice in flash message
                                        $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
                                }
+
+                               //Unattribute session
+                               $session->setApplication(null);
+
+                               //Lock session
+                               $session->setLocked($datetime);
                        }
 
                        }
 
+#                      //Get applications
+#                      $applications = $doctrine->getRepository(Application::class)->findBySession($session);
+#
+#                      //Not empty
+#                      if (!empty($applications)) {
+#                              //Iterate on each applications
+#                              foreach($applications as $application) {
+#                                      //Cancel application
+#                                      $application->setCanceled($canceled);
+#
+#                                      //Update time
+#                                      $application->setUpdated($datetime);
+#
+#                                      //Queue application save
+#                                      $manager->persist($application);
+#
+#                                      //Add notice in flash message
+#                                      $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
+#                              }
+#                      }
+
                        //Update time
                        $session->setUpdated($datetime);
 
                        //Update time
                        $session->setUpdated($datetime);
 
@@ -341,6 +366,10 @@ class SessionController extends DefaultController {
 
                        //Add notice in flash message
                        $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
 
                        //Add notice in flash message
                        $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
+               //Unknown action
+               } else {
+                       //Add warning in flash message
+                       $this->addFlash('warning', $this->translator->trans('Session %id% not updated', ['%id%' => $id]));
                }
 
                //Flush to get the ids
                }
 
                //Flush to get the ids
@@ -385,7 +414,7 @@ class SessionController extends DefaultController {
                                unset($route['_route'], $route['_controller']);
 
                                //Generate url
                                unset($route['_route'], $route['_controller']);
 
                                //Generate url
-                               return $this->redirectToRoute($name, ['session' => $id]+$route);
+                               return $this->redirectToRoute($name, $route);
                        //No route matched
                        } catch(MethodNotAllowedException|ResourceNotFoundException $e) {
                                //Unset referer to fallback to default route
                        //No route matched
                        } catch(MethodNotAllowedException|ResourceNotFoundException $e) {
                                //Unset referer to fallback to default route
@@ -395,273 +424,6 @@ class SessionController extends DefaultController {
 
                //Redirect to cleanup the form
                return $this->redirectToRoute('rapsys_air_session_view', ['id' => $id]);
 
                //Redirect to cleanup the form
                return $this->redirectToRoute('rapsys_air_session_view', ['id' => $id]);
-
-               //Protect session fetching
-               try {
-                       //Fetch session
-                       $session = $doctrine->getRepository(Session::class)->findOneById($id);
-
-                       //Fetch session
-                       $session = $doctrine->getRepository(Session::class)->findOneByLocationSlotDate($data['location'], $data['slot'], $data['date']);
-               //Catch no session case
-               } catch (\Doctrine\ORM\NoResultException $e) {
-                       //Create the session
-                       $session = new Session();
-                       $session->setLocation($data['location']);
-                       $session->setDate($data['date']);
-                       $session->setSlot($data['slot']);
-                       $session->setCreated(new \DateTime('now'));
-                       $session->setUpdated(new \DateTime('now'));
-
-                       //Get short location
-                       $short = $data['location']->getShort();
-
-                       //Get slot
-                       $slot = $data['slot']->getTitle();
-
-                       //Set premium
-                       $session->setPremium($premium = false);
-
-                       //Check if slot is afternoon
-                       //XXX: premium is stored only for Afternoon and Evening
-                       if ($slot == 'Afternoon') {
-                               //Compute premium
-                               //XXX: a session is considered premium a day off
-                               $session->setPremium($premium = $this->isPremium($data['date']));
-                       //Check if slot is evening
-                       //XXX: premium is stored only for Afternoon and Evening
-                       } elseif ($slot == 'Evening') {
-                               //Compute premium
-                               //XXX: a session is considered premium the eve of a day off
-                               $session->setPremium($premium = $this->isPremium((clone $data['date'])->add(new \DateInterval('P1D'))));
-                       //Check if slot is after
-                       } elseif ($slot == 'After') {
-                               //Compute premium
-                               //XXX: a session is considered premium the eve of a day off
-                               $premium = $this->isPremium((clone $data['date'])->add(new \DateInterval('P1D')));
-                       }
-
-                       //Set default length at 6h
-                       //XXX: date part will be truncated on save
-                       $session->setLength(new \DateTime('06:00:00'));
-
-                       //Check if admin
-                       if ($this->isGranted('ROLE_ADMIN')) {
-                               //Check if morning
-                               if ($slot == 'Morning') {
-                                       //Set begin at 9h
-                                       $session->setBegin(new \DateTime('09:00:00'));
-
-                                       //Set length at 5h
-                                       $session->setLength(new \DateTime('05:00:00'));
-                               //Check if afternoon
-                               } elseif ($slot == 'Afternoon') {
-                                       //Set begin at 14h
-                                       $session->setBegin(new \DateTime('14:00:00'));
-
-                                       //Set length at 5h
-                                       $session->setLength(new \DateTime('05:00:00'));
-                               //Check if evening
-                               } elseif ($slot == 'Evening') {
-                                       //Set begin at 19h
-                                       $session->setBegin(new \DateTime('19:00:00'));
-
-                                       //Check if next day is premium
-                                       if ($premium) {
-                                               //Set length at 7h
-                                               $session->setLength(new \DateTime('07:00:00'));
-                                       }
-                               //Check if after
-                               } else {
-                                       //Set begin at 1h
-                                       $session->setBegin(new \DateTime('01:00:00'));
-
-                                       //Set length at 4h
-                                       $session->setLength(new \DateTime('04:00:00'));
-
-                                       //Check if next day is premium
-                                       if ($premium) {
-                                               //Set begin at 2h
-                                               $session->setBegin(new \DateTime('02:00:00'));
-
-                                               //Set length at 3h
-                                               $session->setLength(new \DateTime('03:00:00'));
-                                       }
-                               }
-                       //Docks => 14h -> 19h | 19h -> 01/02h
-                       //XXX: remove Garnier from here to switch back to 21h
-                       } elseif (in_array($short, ['Docks', 'Garnier']) && in_array($slot, ['Afternoon', 'Evening', 'After'])) {
-                               //Check if afternoon
-                               if ($slot == 'Afternoon') {
-                                       //Set begin at 14h
-                                       $session->setBegin(new \DateTime('14:00:00'));
-
-                                       //Set length at 5h
-                                       $session->setLength(new \DateTime('05:00:00'));
-                               //Check if evening
-                               } elseif ($slot == 'Evening') {
-                                       //Set begin at 19h
-                                       $session->setBegin(new \DateTime('19:00:00'));
-
-                                       //Check if next day is premium
-                                       if ($premium) {
-                                               //Set length at 7h
-                                               $session->setLength(new \DateTime('07:00:00'));
-                                       }
-                               //Check if after
-                               } else {
-                                       //Set begin at 1h
-                                       $session->setBegin(new \DateTime('01:00:00'));
-
-                                       //Set length at 4h
-                                       $session->setLength(new \DateTime('04:00:00'));
-
-                                       //Check if next day is premium
-                                       if ($premium) {
-                                               //Set begin at 2h
-                                               $session->setBegin(new \DateTime('02:00:00'));
-
-                                               //Set length at 3h
-                                               $session->setLength(new \DateTime('03:00:00'));
-                                       }
-                               }
-                       //Garnier => 21h -> 01/02h
-                       } elseif ($short == 'Garnier' && in_array($slot, ['Evening', 'After'])) {
-                               //Check if evening
-                               if ($slot == 'Evening') {
-                                       //Set begin at 21h
-                                       $session->setBegin(new \DateTime('21:00:00'));
-
-                                       //Set length at 5h
-                                       $session->setLength(new \DateTime('05:00:00'));
-
-                                       //Check if next day is premium
-                                       if ($premium) {
-                                               //Set length at 6h
-                                               $session->setLength(new \DateTime('06:00:00'));
-                                       }
-                               //Check if after
-                               } else {
-                                       //Set begin at 1h
-                                       $session->setBegin(new \DateTime('01:00:00'));
-
-                                       //Set length at 4h
-                                       $session->setLength(new \DateTime('04:00:00'));
-
-                                       //Check if next day is premium
-                                       if ($premium) {
-                                               //Set begin at 2h
-                                               $session->setBegin(new \DateTime('02:00:00'));
-
-                                               //Set length at 3h
-                                               $session->setLength(new \DateTime('03:00:00'));
-                                       }
-                               }
-                       //Trocadero|Tokyo|Swan|Honore|Orsay => 19h -> 01/02h
-                       } elseif (in_array($short, ['Trocadero', 'Tokyo', 'Swan', 'Honore', 'Orsay']) && in_array($slot, ['Evening', 'After'])) {
-                               //Check if evening
-                               if ($slot == 'Evening') {
-                                       //Set begin at 19h
-                                       $session->setBegin(new \DateTime('19:00:00'));
-
-                                       //Check if next day is premium
-                                       if ($premium) {
-                                               //Set length at 7h
-                                               $session->setLength(new \DateTime('07:00:00'));
-                                       }
-                               //Check if after
-                               } else {
-                                       //Set begin at 1h
-                                       $session->setBegin(new \DateTime('01:00:00'));
-
-                                       //Set length at 4h
-                                       $session->setLength(new \DateTime('04:00:00'));
-
-                                       //Check if next day is premium
-                                       if ($premium) {
-                                               //Set begin at 2h
-                                               $session->setBegin(new \DateTime('02:00:00'));
-
-                                               //Set length at 3h
-                                               $session->setLength(new \DateTime('03:00:00'));
-                                       }
-                               }
-                       //La Villette => 14h -> 19h
-                       } elseif ($short == 'Villette' && $slot == 'Afternoon') {
-                               //Set begin at 14h
-                               $session->setBegin(new \DateTime('14:00:00'));
-
-                               //Set length at 5h
-                               $session->setLength(new \DateTime('05:00:00'));
-                       //Place Colette => 14h -> 21h
-                       //TODO: add check here that it's a millegaux account ?
-                       } elseif ($short == 'Colette' && $slot == 'Afternoon') {
-                               //Set begin at 14h
-                               $session->setBegin(new \DateTime('14:00:00'));
-
-                               //Set length at 7h
-                               $session->setLength(new \DateTime('07:00:00'));
-                       //Galerie d'OrlĆ©ans => 14h -> 18h
-                       } elseif ($short == 'Orleans' && $slot == 'Afternoon') {
-                               //Set begin at 14h
-                               $session->setBegin(new \DateTime('14:00:00'));
-
-                               //Set length at 4h
-                               $session->setLength(new \DateTime('04:00:00'));
-                       //Combination not supported
-                       } else {
-                               //Add error in flash message
-                               $this->addFlash('error', $this->translator->trans('Session on %date% %location% %slot% not yet supported', ['%location%' => $this->translator->trans('at '.$data['location']), '%slot%' => $this->translator->trans('the '.strtolower($data['slot'])), '%date%' => $data['date']->format('Y-m-d')]));
-                       }
-
-                       //Queue session save
-                       $manager->persist($session);
-
-                       //Flush to get the ids
-                       #$manager->flush();
-
-                       $this->addFlash('notice', $this->translator->trans('Session on %date% %location% %slot% created', ['%location%' => $this->translator->trans('at '.$data['location']), '%slot%' => $this->translator->trans('the '.strtolower($data['slot'])), '%date%' => $data['date']->format('Y-m-d')]));
-               }
-
-               //Set user
-               $user = $this->getUser();
-
-               //Replace with requested user for admin
-               if ($this->isGranted('ROLE_ADMIN') && !empty($data['user'])) {
-                       $user = $this->getDoctrine()->getRepository(User::class)->findOneById($data['user']);
-               }
-
-               //Protect application fetching
-               try {
-                       //Retrieve application
-                       $application = $doctrine->getRepository(Application::class)->findOneBySessionUser($session, $user);
-
-                       //Add warning in flash message
-                       $this->addFlash('warning', $this->translator->trans('Application on %date% %location% %slot% already exists', ['%location%' => $this->translator->trans('at '.$data['location']), '%slot%' => $this->translator->trans('the '.strtolower($data['slot'])), '%date%' => $data['date']->format('Y-m-d')]));
-               //Catch no application and session without identifier (not persisted&flushed) cases
-               } catch (\Doctrine\ORM\NoResultException|\Doctrine\ORM\ORMInvalidArgumentException $e) {
-                       //Create the application
-                       $application = new Application();
-                       $application->setSession($session);
-                       $application->setUser($user);
-                       $application->setCreated(new \DateTime('now'));
-                       $application->setUpdated(new \DateTime('now'));
-
-                       //Refresh session updated field
-                       $session->setUpdated(new \DateTime('now'));
-
-                       //Queue session save
-                       $manager->persist($session);
-
-                       //Queue application save
-                       $manager->persist($application);
-
-                       //Flush to get the ids
-                       $manager->flush();
-
-                       //Add notice in flash message
-                       $this->addFlash('notice', $this->translator->trans('Application on %date% %location% %slot% created', ['%location%' => $this->translator->trans('at '.$data['location']), '%slot%' => $this->translator->trans('the '.strtolower($data['slot'])), '%date%' => $data['date']->format('Y-m-d')]));
-               }
        }
 
        /**
        }
 
        /**
@@ -673,51 +435,26 @@ class SessionController extends DefaultController {
         *
         * @return Response The rendered view
         */
         *
         * @return Response The rendered view
         */
-       public function index(Request $request = null) {
+       public function index(Request $request): Response {
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
                //Set section
                $section = $this->translator->trans('Sessions');
 
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
                //Set section
                $section = $this->translator->trans('Sessions');
 
-               //Set title
-               $title = $section.' - '.$this->translator->trans($this->config['site']['title']);
-
-               //Init context
-               $context = [];
+               //Set description
+               $this->context['description'] = $this->translator->trans('Libre Air session list');
 
 
-               //Create application form for role_guest
-               if ($this->isGranted('ROLE_GUEST')) {
-                       //Create ApplicationType form
-                       $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [
-                               //Set the action
-                               'action' => $this->generateUrl('rapsys_air_application_add'),
-                               //Set the form attribute
-                               'attr' => [ 'class' => 'col' ],
-                               //Set admin
-                               'admin' => $this->isGranted('ROLE_ADMIN'),
-                               //Set default user to current
-                               'user' => $this->getUser()->getId(),
-                               //Set default slot to evening
-                               //XXX: default to Evening (3)
-                               'slot' => $doctrine->getRepository(Slot::class)->findOneById(3)
-                       ]);
-
-                       //Add form to context
-                       $context['application'] = $application->createView();
-               //Create login form for anonymous
-               } elseif (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
-                       //Create ApplicationType form
-                       $login = $this->createForm('Rapsys\UserBundle\Form\LoginType', null, [
-                               //Set the action
-                               'action' => $this->generateUrl('rapsys_user_login'),
-                               //Set the form attribute
-                               'attr' => [ 'class' => 'col' ]
-                       ]);
+               //Set keywords
+               $this->context['keywords'] = [
+                       $this->translator->trans('sessions'),
+                       $this->translator->trans('session list'),
+                       $this->translator->trans('listing'),
+                       $this->translator->trans('Libre Air')
+               ];
 
 
-                       //Add form to context
-                       $context['login'] = $login->createView();
-               }
+               //Set title
+               $title = $this->translator->trans($this->config['site']['title']).' - '.$section;
 
                //Compute period
                $period = new \DatePeriod(
 
                //Compute period
                $period = new \DatePeriod(
@@ -726,7 +463,9 @@ class SessionController extends DefaultController {
                        //Iterate on each day
                        new \DateInterval('P1D'),
                        //End with next sunday and 4 weeks
                        //Iterate on each day
                        new \DateInterval('P1D'),
                        //End with next sunday and 4 weeks
-                       new \DateTime('Monday this week + 5 week')
+                       new \DateTime(
+                               $this->isGranted('IS_AUTHENTICATED_REMEMBERED')?'Monday this week + 4 week':'Monday this week + 2 week'
+                       )
                );
 
                //Fetch calendar
                );
 
                //Fetch calendar
@@ -735,10 +474,10 @@ class SessionController extends DefaultController {
 
                //Fetch locations
                //XXX: we want to display all active locations anyway
 
                //Fetch locations
                //XXX: we want to display all active locations anyway
-               $locations = $doctrine->getRepository(Location::class)->fetchTranslatedLocationByDatePeriod($this->translator, $period/*, !$this->isGranted('IS_AUTHENTICATED_REMEMBERED')*/);
+               $locations = $doctrine->getRepository(Location::class)->findTranslatedSortedByPeriod($this->translator, $period);
 
                //Render the view
 
                //Render the view
-               return $this->render('@RapsysAir/session/index.html.twig', ['title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+$context+$this->context);
+               return $this->render('@RapsysAir/session/index.html.twig', ['title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+$this->context);
        }
 
        /**
        }
 
        /**
@@ -751,26 +490,41 @@ class SessionController extends DefaultController {
         *
         * @return Response The rendered view
         */
         *
         * @return Response The rendered view
         */
-       public function view(Request $request, $id) {
+       public function view(Request $request, $id): Response {
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
                //Fetch session
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
                //Fetch session
-               $session = $doctrine->getRepository(Session::class)->fetchOneById($id);
+               if (empty($session = $doctrine->getRepository(Session::class)->fetchOneById($id, $request->getLocale()))) {
+                       throw $this->createNotFoundException($this->translator->trans('Unable to find session: %id%', ['%id%' => $id]));
+               }
 
                //Set section
                $section = $this->translator->trans($session['l_title']);
 
 
                //Set section
                $section = $this->translator->trans($session['l_title']);
 
-               //Set title
-               $title = $this->translator->trans('Session %id%', ['%id%' => $id]).' - '.$section.' - '.$this->translator->trans($this->config['site']['title']);
+               //Set localization date formater
+               $intl = new \IntlDateFormatter($request->getLocale(), \IntlDateFormatter::GREGORIAN, \IntlDateFormatter::SHORT);
+
+               //Set description
+               $this->context['description'] = $this->translator->trans('Outdoor Argentine Tango session the %date%', [ '%date%' => $intl->format($session['start']) ]);
+
+               //Set keywords
+               $this->context['keywords'] = [
+                       $this->translator->trans('outdoor'),
+                       $this->translator->trans('Argentine Tango'),
+               ];
 
 
-               //Init context
-               $context = [];
+               //With granted session
+               if (!empty($session['au_id'])) {
+                       $this->context['keywords'][0] = $session['au_pseudonym'];
+               }
+               //Set title
+               $title = $this->translator->trans($this->config['site']['title']).' - '.$section.' - '.$this->translator->trans(!empty($session['au_id'])?'Session %id% by %pseudonym%':'Session %id%', ['%id%' => $id, '%pseudonym%' => $session['au_pseudonym']]);
 
                //Create application form for role_guest
                if ($this->isGranted('ROLE_GUEST')) {
                        //Create ApplicationType form
 
                //Create application form for role_guest
                if ($this->isGranted('ROLE_GUEST')) {
                        //Create ApplicationType form
-                       $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [
+                       $applicationForm = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [
                                //Set the action
                                'action' => $this->generateUrl('rapsys_air_application_add'),
                                //Set the form attribute
                                //Set the action
                                'action' => $this->generateUrl('rapsys_air_application_add'),
                                //Set the form attribute
@@ -786,13 +540,13 @@ class SessionController extends DefaultController {
                        ]);
 
                        //Add form to context
                        ]);
 
                        //Add form to context
-                       $context['application'] = $application->createView();
+                       $this->context['forms']['application'] = $applicationForm->createView();
 
                        //Set now
                        $now = new \DateTime('now');
 
 
                        //Set now
                        $now = new \DateTime('now');
 
-                       //Create SessionEditType form
-                       $session_edit = $this->createForm('Rapsys\AirBundle\Form\SessionEditType', null, [
+                       //Create SessionType form
+                       $sessionForm = $this->createForm('Rapsys\AirBundle\Form\SessionType', null, [
                                //Set the action
                                'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]),
                                //Set the form attribute
                                //Set the action
                                'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]),
                                //Set the form attribute
@@ -806,31 +560,21 @@ class SessionController extends DefaultController {
                                //Set length
                                'length' => $session['length'],
                                //Set raincancel
                                //Set length
                                'length' => $session['length'],
                                //Set raincancel
-                               'raincancel' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['rainfall'] >= 2,
+                               'raincancel' => ($this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id']) && $session['rainfall'] >= 2,
                                //Set cancel
                                'cancel' => $this->isGranted('ROLE_ADMIN') || in_array($this->getUser()->getId(), explode("\n", $session['sau_id'])),
                                //Set modify
                                'modify' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_REGULAR'),
                                //Set move
                                'move' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_SENIOR'),
                                //Set cancel
                                'cancel' => $this->isGranted('ROLE_ADMIN') || in_array($this->getUser()->getId(), explode("\n", $session['sau_id'])),
                                //Set modify
                                'modify' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_REGULAR'),
                                //Set move
                                'move' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_SENIOR'),
+                               //Set attribute
+                               'attribute' => $this->isGranted('ROLE_ADMIN') && $session['locked'] === null,
                                //Set session
                                'session' => $session['id']
                        ]);
 
                        //Add form to context
                                //Set session
                                'session' => $session['id']
                        ]);
 
                        //Add form to context
-                       $context['session_edit'] = $session_edit->createView();
-               //Create login form for anonymous
-               } elseif (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
-                       //Create ApplicationType form
-                       $login = $this->createForm('Rapsys\UserBundle\Form\LoginType', null, [
-                               //Set the action
-                               'action' => $this->generateUrl('rapsys_user_login'),
-                               //Set the form attribute
-                               'attr' => [ 'class' => 'col' ]
-                       ]);
-
-                       //Add form to context
-                       $context['login'] = $login->createView();
+                       $this->context['forms']['session'] = $sessionForm->createView();
                }
 
                //Add session in context
                }
 
                //Add session in context
@@ -869,6 +613,15 @@ class SessionController extends DefaultController {
                                'id' => $session['t_id'],
                                'title' => $this->translator->trans($session['t_title'])
                        ],
                                'id' => $session['t_id'],
                                'title' => $this->translator->trans($session['t_title'])
                        ],
+                       'snippet' => [
+                               'id' => $session['p_id'],
+                               'description' => $session['p_description'],
+                               'class' => $session['p_class'],
+                               'contact' => $session['p_contact'],
+                               'donate' => $session['p_donate'],
+                               'link' => $session['p_link'],
+                               'profile' => $session['p_profile']
+                       ],
                        'applications' => null
                ];
 
                        'applications' => null
                ];
 
@@ -877,9 +630,11 @@ class SessionController extends DefaultController {
                        $context['session']['application'] = [
                                'user' => [
                                        'id' => $session['au_id'],
                        $context['session']['application'] = [
                                'user' => [
                                        'id' => $session['au_id'],
+                                       'by' => $this->translator->trans('by %pseudonym%', [ '%pseudonym%' => $session['au_pseudonym'] ]),
                                        'title' => $session['au_pseudonym']
                                ],
                                'id' => $session['a_id'],
                                        'title' => $session['au_pseudonym']
                                ],
                                'id' => $session['a_id'],
+                               'canceled' => $session['a_canceled'],
                                'title' => $this->translator->trans('Application %id%', [ '%id%' => $session['a_id'] ]),
                        ];
                }
                                'title' => $this->translator->trans('Application %id%', [ '%id%' => $session['a_id'] ]),
                        ];
                }
@@ -923,7 +678,23 @@ class SessionController extends DefaultController {
                        }
                }
 
                        }
                }
 
+               //Compute period
+               $period = new \DatePeriod(
+                       //Start from first monday of week
+                       new \DateTime('Monday this week'),
+                       //Iterate on each day
+                       new \DateInterval('P1D'),
+                       //End with next sunday and 4 weeks
+                       new \DateTime(
+                               $this->isGranted('IS_AUTHENTICATED_REMEMBERED')?'Monday this week + 4 week':'Monday this week + 2 week'
+                       )
+               );
+
+               //Fetch locations
+               //XXX: we want to display all active locations anyway
+               $locations = $doctrine->getRepository(Location::class)->findTranslatedSortedByPeriod($this->translator, $period, $session['au_id']);
+
                //Render the view
                //Render the view
-               return $this->render('@RapsysAir/session/view.html.twig', ['title' => $title, 'section' => $section]+$context+$this->context);
+               return $this->render('@RapsysAir/session/view.html.twig', ['title' => $title, 'section' => $section, 'locations' => $locations]+$context+$this->context);
        }
 }
        }
 }