- $context['login'] = $login->createView();
- }
-
- //Add session in context
- $context['session'] = [
- 'id' => $id,
- 'date' => $session['date'],
- 'begin' => $session['begin'],
- 'start' => $session['start'],
- 'length' => $session['length'],
- 'stop' => $session['stop'],
- 'rainfall' => $session['rainfall'] !== null ? $session['rainfall'].' mm' : $session['rainfall'],
- 'rainrisk' => $session['rainrisk'] !== null ? ($session['rainrisk']*100).' %' : $session['rainrisk'],
- 'realfeel' => $session['realfeel'] !== null ? $session['realfeel'].' °C' : $session['realfeel'],
- 'realfeelmin' => $session['realfeelmin'] !== null ? $session['realfeelmin'].' °C' : $session['realfeelmin'],
- 'realfeelmax' => $session['realfeelmax'] !== null ? $session['realfeelmax'].' °C' : $session['realfeelmax'],
- 'temperature' => $session['temperature'] !== null ? $session['temperature'].' °C' : $session['temperature'],
- 'temperaturemin' => $session['temperaturemin'] !== null ? $session['temperaturemin'].' °C' : $session['temperaturemin'],
- 'temperaturemax' => $session['temperaturemax'] !== null ? $session['temperaturemax'].' °C' : $session['temperaturemax'],
- 'locked' => $session['locked'],
- 'created' => $session['created'],
- 'updated' => $session['updated'],
- 'title' => $this->translator->trans('Session %id%', ['%id%' => $id]),
- 'application' => null,
- 'location' => [
- 'id' => $session['l_id'],
- 'at' => $this->translator->trans('at '.$session['l_title']),
- 'short' => $this->translator->trans($session['l_short']),
- 'title' => $this->translator->trans($session['l_title']),
- 'address' => $session['l_address'],
- 'zipcode' => $session['l_zipcode'],
- 'city' => $session['l_city'],
- 'latitude' => $session['l_latitude'],
- 'longitude' => $session['l_longitude']
- ],
- 'slot' => [
- 'id' => $session['t_id'],
- 'title' => $this->translator->trans($session['t_title'])
- ],
- 'applications' => null
- ];
-
- //With application
- if (!empty($session['a_id'])) {
- $context['session']['application'] = [
- 'user' => [
- 'id' => $session['au_id'],
- 'title' => $session['au_pseudonym']
- ],
- 'id' => $session['a_id'],
- 'title' => $this->translator->trans('Application %id%', [ '%id%' => $session['a_id'] ]),
- ];
- }
-
- //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]
- ];
- }
- }