- //With applications
- if (!empty($session['sa_id'])) {
- //Extract applications id
- $session['sa_id'] = explode("\n", $session['sa_id']);
- //Extract applications score
- //XXX: score may be null before grant or for bad behaviour, replace NULL with 'NULL' to avoid silent drop in mysql
- $session['sa_score'] = array_map(function($v){return $v==='NULL'?null:$v;}, explode("\n", $session['sa_score']));
- //Extract applications created
- $session['sa_created'] = array_map(function($v){return new \DateTime($v);}, explode("\n", $session['sa_created']));
- //Extract applications updated
- $session['sa_updated'] = array_map(function($v){return new \DateTime($v);}, explode("\n", $session['sa_updated']));
- //Extract applications canceled
- //XXX: canceled is null before cancelation, replace NULL with 'NULL' to avoid silent drop in mysql
- $session['sa_canceled'] = array_map(function($v){return $v==='NULL'?null:new \DateTime($v);}, explode("\n", $session['sa_canceled']));
-
- //Extract applications user id
- $session['sau_id'] = explode("\n", $session['sau_id']);
- //Extract applications user pseudonym
- $session['sau_pseudonym'] = explode("\n", $session['sau_pseudonym']);
-
- //Init applications
- $context['session']['applications'] = [];
- foreach($session['sa_id'] as $i => $sa_id) {
- $context['session']['applications'][$sa_id] = [
- 'user' => null,
- 'score' => $session['sa_score'][$i],
- 'created' => $session['sa_created'][$i],
- 'updated' => $session['sa_updated'][$i],
- 'canceled' => $session['sa_canceled'][$i]
- ];
- if (!empty($session['sau_id'][$i])) {
- $context['session']['applications'][$sa_id]['user'] = [
- 'id' => $session['sau_id'][$i],
- 'title' => $session['sau_pseudonym'][$i]
- ];
+ //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]));