+
+ //Get location
+ $location = $data['location']->getTitle();
+
+ //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('15:30:00'));
+
+ //Set length at 5h
+ $session->setLength(new \DateTime('05:30:00'));
+ //Check if evening
+ } elseif ($slot == 'Evening') {
+ //Set begin at 19h00
+ $session->setBegin(new \DateTime('19:30:00'));
+
+ //Set length at 5h
+ $session->setLength(new \DateTime('05:30:00'));
+
+ //Check if next day is premium
+ if ($premium) {
+ //Set length at 7h
+ $session->setLength(new \DateTime('06: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'));
+ }
+ }
+ //Tino-Rossi garden => 14h -> 19h | 19h -> 01/02h
+ } elseif (in_array($location, ['Tino-Rossi garden']) && 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 opera => 21h -> 01/02h
+ } elseif ($location == 'Garnier opera' && 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 esplanade|Tokyo palace|Swan island|Saint-Honore market|Orsay museum => 19h -> 01/02h
+ } elseif (in_array($location, ['Trocadero esplanade', 'Tokyo palace', 'Swan island', 'Saint-Honore market', 'Orsay museum']) && 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'));
+ }
+ }
+ //Drawings' garden (Villette) => 14h -> 19h
+ } elseif ($location == 'Drawings\' garden' && $slot == 'Afternoon') {
+ //Set begin at 14h
+ $session->setBegin(new \DateTime('14:00:00'));
+
+ //Set length at 5h
+ $session->setLength(new \DateTime('05:00:00'));
+ //Colette place => 14h -> 21h
+ //TODO: add check here that it's a millegaux account ?
+ } elseif ($location == 'Colette place' && $slot == 'Afternoon') {
+ //Set begin at 14h
+ $session->setBegin(new \DateTime('14:00:00'));
+
+ //Set length at 7h
+ $session->setLength(new \DateTime('07:00:00'));
+ //Orleans gallery => 14h -> 18h
+ } elseif ($location == 'Orleans gallery' && $slot == 'Afternoon') {
+ //Set begin at 14h
+ $session->setBegin(new \DateTime('14:00:00'));
+
+ //Set length at 4h
+ $session->setLength(new \DateTime('04:00:00'));
+ //Monde garden => 14h -> 19h
+ //TODO: add check here that it's a raphael account ?
+ } elseif ($location == 'Monde garden' && $slot == 'Afternoon') {
+ //Set begin at 14h
+ $session->setBegin(new \DateTime('14:00:00'));
+
+ //Set length at 4h
+ $session->setLength(new \DateTime('05:00:00'));
+ //Combination not supported
+ //TODO: add Madeleine place|Bastille place|Vendome place ?
+ } 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(strval($data['slot']))), '%date%' => $data['date']->format('Y-m-d')]));
+
+ //Set title
+ $title = $this->translator->trans('Application add');
+
+ //Render the view
+ return $this->render('@RapsysAir/application/add.html.twig', ['title' => $title, '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(strval($data['slot']))), '%date%' => $data['date']->format('Y-m-d')]));
+
+ //Set title
+ $title = $this->translator->trans('Application add');
+
+ //Render the view
+ return $this->render('@RapsysAir/application/add.html.twig', ['title' => $title, 'form' => $form->createView()]+$this->context);
+ }