+
+ //With raincancel and application and (rainfall or admin)
+ if ($action['raincancel'] && ($application = $sessionObject->getApplication()) && ($sessionObject->getRainfall() >= 2 || $this->checker->isGranted('ROLE_ADMIN'))) {
+ //Cancel application at start minus one day
+ $application->setCanceled($canceled);
+
+ //Update time
+ $application->setUpdated($datetime);
+
+ //Insufficient rainfall
+ //XXX: is admin
+ if ($sessionObject->getRainfall() < 2) {
+ //Set score
+ //XXX: magic cheat score 42
+ $application->setScore(42);
+ }
+
+ //Queue application save
+ $this->manager->persist($application);
+
+ //Add notice in flash message
+ $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
+
+ //Update time
+ $sessionObject->setUpdated($datetime);
+
+ //Queue session save
+ $this->manager->persist($sessionObject);
+
+ //Add notice in flash message
+ $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
+ //With modify
+ } elseif ($action['modify']) {
+ //With admin
+ if ($this->checker->isGranted('ROLE_ADMIN')) {
+ //Get application
+ $application = $this->doctrine->getRepository(Application::class)->findOneBySessionUser($sessionObject, $userObject);
+
+ //Set dance
+ $application->setDance($data['dance']);
+
+ //Queue session save
+ $this->manager->persist($application);
+
+ //Set slot
+ $sessionObject->setSlot($data['slot']);
+
+ //Set date
+ $sessionObject->setDate($data['date']);
+ }
+
+ //Set begin
+ $sessionObject->setBegin($data['begin']);
+
+ //Set length
+ $sessionObject->setLength($data['length']);
+
+ //Update time
+ $sessionObject->setUpdated($datetime);
+
+ //Queue session save
+ $this->manager->persist($sessionObject);
+
+ //Add notice in flash message
+ $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
+ //With move
+ } elseif ($action['move']) {
+ //Set location
+ $sessionObject->setLocation($this->doctrine->getRepository(Location::class)->findOneById($data['location']));
+
+ //Update time
+ $sessionObject->setUpdated($datetime);
+
+ //Queue session save
+ $this->manager->persist($sessionObject);
+
+ //Add notice in flash message
+ $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
+ //With cancel or forcecancel
+ } elseif ($action['cancel'] || $action['forcecancel']) {
+ //Get application
+ $application = $this->doctrine->getRepository(Application::class)->findOneBySessionUser($sessionObject, $userObject);
+
+ //Not already canceled
+ if ($application->getCanceled() === null) {
+ //Cancel application
+ $application->setCanceled($datetime);
+
+ //Check if application is session application and (canceled 24h before start or forcecancel (as admin))
+ #if ($sessionObject->getApplication() == $application && ($datetime < $canceled || $action['forcecancel'])) {
+ if ($sessionObject->getApplication() == $application && $action['forcecancel']) {
+ //Set score
+ //XXX: magic cheat score 42
+ $application->setScore(42);
+
+ //Unattribute session
+ $sessionObject->setApplication(null);
+
+ //Update time
+ $sessionObject->setUpdated($datetime);
+
+ //Queue session save
+ $this->manager->persist($sessionObject);
+
+ //Add notice in flash message
+ $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
+ }
+ //Already canceled
+ } else {
+ //Uncancel application
+ $application->setCanceled(null);
+ }
+
+ //Update time
+ $application->setUpdated($datetime);
+
+ //Queue application save
+ $this->manager->persist($application);
+
+ //Add notice in flash message
+ $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
+ //With attribute
+ } elseif ($action['attribute']) {
+ //Get application
+ $application = $this->doctrine->getRepository(Application::class)->findOneBySessionUser($sessionObject, $userObject);
+
+ //Already canceled
+ if ($application->getCanceled() !== null) {
+ //Uncancel application
+ $application->setCanceled(null);
+ }
+
+ //Set score
+ //XXX: magic cheat score 42
+ $application->setScore(42);
+
+ //Update time
+ $application->setUpdated($datetime);
+
+ //Queue application save
+ $this->manager->persist($application);
+
+ //Add notice in flash message
+ $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
+
+ //Unattribute session
+ $sessionObject->setApplication($application);
+
+ //Update time
+ $sessionObject->setUpdated($datetime);
+
+ //Queue session save
+ $this->manager->persist($sessionObject);
+
+ //Add notice in flash message
+ $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
+ //With autoattribute
+ } elseif ($action['autoattribute']) {
+ //Get best application
+ //XXX: best application may not issue result while grace time or bad behaviour
+ if (!empty($application = $this->doctrine->getRepository(Session::class)->findBestApplicationById($id))) {
+ //Attribute session
+ $sessionObject->setApplication($application);
+
+ //Update time
+ $sessionObject->setUpdated($datetime);
+
+ //Queue session save
+ $this->manager->persist($sessionObject);
+
+ //Add notice in flash message
+ $this->addFlash('notice', $this->translator->trans('Session %id% auto attributed', ['%id%' => $id]));
+ //No application
+ } else {
+ //Add warning in flash message
+ $this->addFlash('warning', $this->translator->trans('Session %id% not auto attributed', ['%id%' => $id]));
+ }
+ //With lock
+ } elseif ($action['lock']) {
+ //Already locked
+ if ($sessionObject->getLocked() !== null) {
+ //Set uncanceled
+ $canceled = null;
+
+ //Unlock session
+ $sessionObject->setLocked(null);
+ //Not locked
+ } else {
+ //Get application
+ if ($application = $sessionObject->getApplication()) {
+ //Set score
+ //XXX: magic cheat score 42
+ $application->setScore(42);
+
+ //Update time
+ $application->setUpdated($datetime);
+
+ //Queue application save
+ $this->manager->persist($application);
+
+ //Add notice in flash message
+ $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()]));
+ }
+
+ //Unattribute session
+ $sessionObject->setApplication(null);
+
+ //Lock session
+ $sessionObject->setLocked($datetime);
+ }
+
+ //Update time
+ $sessionObject->setUpdated($datetime);
+
+ //Queue session save
+ $this->manager->persist($sessionObject);
+
+ //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]));