+ //Get short location
+ $short = $data['location']->getShort();
+
+ //Get slot
+ $slot = $data['slot']->getTitle();
+
+ //Get premium
+ //XXX: premium is stored only for Afternoon and Evening
+ $premium = $session->isPremium();
+
+ //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 18h
+ $session->setBegin(new \DateTime('18:00:00'));
+
+ //Set length at 5h
+ $session->setLength(new \DateTime('05:00:00'));
+
+ //Check if next day is premium
+ if ($premium) {
+ //Set length at 5h
+ $session->setLength(new \DateTime('07:00:00'));
+ }
+ //Check if evening
+ } elseif ($slot == 'Evening') {
+ //Set begin at 20h30
+ $session->setBegin(new \DateTime('20:00:00'));
+
+ //Check if next day is premium
+ if ($premium) {
+ //Set length at 7h
+ $session->setLength(new \DateTime('07:00:00'));
+ }
+
+ //Set length at 4h
+ #$session->setLength(new \DateTime('04:30: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'));
+ //Jardin du Monde => 14h -> 15h
+ } elseif ($short == 'Monde' && $slot == 'Morning') {
+ //Set begin at 14h
+ $session->setBegin(new \DateTime('14:00:00'));
+
+ //Set length at 4h
+ $session->setLength(new \DateTime('01: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')]));
+
+ //Set section
+ $section = $this->translator->trans('Application add');
+
+ //Set title
+ $title = $this->translator->trans($this->config['site']['title']).' - '.$section;
+
+ //Render the view
+ return $this->render('@RapsysAir/application/add.html.twig', ['title' => $title, 'section' => $section, 'form' => $form->createView()]+$this->context);
+ }
+
+ //Check if admin
+ if (!$this->isGranted('ROLE_ADMIN') && $session->getStart() < new \DateTime('00:00:00')) {
+ //Add error in flash message
+ $this->addFlash('error', $this->translator->trans('Session in the past 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')]));
+
+ //Set section
+ $section = $this->translator->trans('Application add');
+
+ //Set title
+ $title = $this->translator->trans($this->config['site']['title']).' - '.$section;
+
+ //Render the view
+ return $this->render('@RapsysAir/application/add.html.twig', ['title' => $title, 'section' => $section, 'form' => $form->createView()]+$this->context);
+ }
+