1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys AirBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\AirBundle\Controller
;
14 use Symfony\Component\Asset\Packages
;
15 use Symfony\Component\Filesystem\Exception\IOExceptionInterface
;
16 use Symfony\Component\Filesystem\Filesystem
;
17 use Symfony\Component\HttpFoundation\BinaryFileResponse
;
18 use Symfony\Component\HttpFoundation\Request
;
19 use Symfony\Component\HttpFoundation\Response
;
20 use Symfony\Component\Routing\Exception\MethodNotAllowedException
;
21 use Symfony\Component\Routing\Exception\ResourceNotFoundException
;
22 use Symfony\Component\Routing\Generator\UrlGeneratorInterface
;
23 use Symfony\Component\Routing\RequestContext
;
25 use Rapsys\AirBundle\Entity\Application
;
26 use Rapsys\AirBundle\Entity\User
;
27 use Rapsys\AirBundle\Entity\Slot
;
28 use Rapsys\AirBundle\Entity\Session
;
29 use Rapsys\AirBundle\Entity\Location
;
31 class SessionController
extends AbstractController
{
35 * @desc Persist session and all required dependencies in database
37 * @param Request $request The request instance
39 * @return Response The rendered view or redirection
41 * @throws \RuntimeException When user has not at least guest role
43 public function edit(Request
$request, $id): Response
{
44 //Prevent non-guest to access here
45 $this->denyAccessUnlessGranted('ROLE_GUEST', null, $this->translator
->trans('Unable to access this page without role %role%!', ['%role%' => $this->translator
->trans('Guest')]));
47 //Reject non post requests
48 if (!$request->isMethod('POST')) {
49 throw new \
RuntimeException('Request method MUST be POST');
53 $doctrine = $this->getDoctrine();
56 $locale = $request->getLocale();
59 $session = $doctrine->getRepository(Session
::class)->fetchOneById($id, $locale);
64 !$this->isGranted('ROLE_ADMIN') &&
66 $this->getUser()->getId() != $session['au_id'] &&
67 //or application without attributed user
68 $session['au_id'] !== null && !in_array($this->getUser()->getId(), explode("\n", $session['sau_id']))
70 //Prevent non admin and non attributed user access
71 throw $this->createAccessDeniedException();
75 $now = new \
DateTime('now');
77 //Create SessionType form
78 $form = $this->createForm('Rapsys\AirBundle\Form\SessionType', null, [
80 'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]),
81 //Set the form attribute
84 'admin' => $this->isGranted('ROLE_ADMIN'),
85 //Set default user to current
86 'user' => $this->getUser()->getId(),
88 'date' => $session['date'],
90 'begin' => $session['begin'],
92 'length' => $session['length'],
94 'raincancel' => ($this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id']) && $session['rainfall'] >= 2,
96 'cancel' => $this->isGranted('ROLE_ADMIN') || in_array($this->getUser()->getId(), explode("\n", $session['sau_id'])),
98 'modify' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_REGULAR'),
100 'move' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_SENIOR'),
102 'attribute' => $this->isGranted('ROLE_ADMIN') && $session['locked'] === null,
104 'session' => $session['id']
107 //Refill the fields in case of invalid form
108 $form->handleRequest($request);
110 //Handle invalid data
111 if (!$form->isSubmitted() || !$form->isValid()) {
113 $this->context
['title'] = $this->translator
->trans(!empty($session['au_id'])?'Session %id% by %pseudonym%':'Session %id%', ['%id%' => $id, '%pseudonym%' => $session['au_pseudonym']]);
116 $this->context
['facebook']['metas']['og:title'] = $this->context
['title'].' '.$this->translator
->trans('at '.$session['l_title']);
119 $this->context
['section'] = $this->translator
->trans($session['l_title']);
121 //Set localization date formater
122 $intl = new \
IntlDateFormatter($locale, \IntlDateFormatter
::GREGORIAN
, \IntlDateFormatter
::SHORT
);
125 $this->context
['description'] = $this->translator
->trans('Outdoor Argentine Tango session the %date%', [ '%date%' => $intl->format($session['start']) ]);
127 //Set localization date formater
128 $intlDate = new \
IntlDateFormatter($locale, \IntlDateFormatter
::TRADITIONAL
, \IntlDateFormatter
::NONE
);
130 //Set localization time formater
131 $intlTime = new \
IntlDateFormatter($locale, \IntlDateFormatter
::NONE
, \IntlDateFormatter
::SHORT
);
134 $this->context
['facebook'] +
= [
136 $session['au_pseudonym'] => [
137 'font' => 'irishgrover',
140 ucfirst($intlDate->format($session['start']))."\n".$this->translator
->trans('From %start% to %stop%', ['%start%' => $intlTime->format($session['start']), '%stop%' => $intlTime->format($session['stop'])]) => [
143 $this->translator
->trans('at '.$session['l_title']) => [
145 'font' => 'labelleaurore',
149 'updated' => $session['updated']->format('U')
152 //Add session in context
153 $this->context
['session'] = [
155 'title' => $this->translator
->trans('Session %id%', ['%id%' => $id]),
157 'id' => $session['l_id'],
158 'at' => $this->translator
->trans('at '.$session['l_title'])
163 return $this->render('@RapsysAir/session/edit.html.twig', ['form' => $form->createView()]+
$this->context
);
167 $manager = $doctrine->getManager();
170 $data = $form->getData();
173 $session = $doctrine->getRepository(Session
::class)->findOneById($id);
176 $user = $this->getUser();
178 //Replace with requested user for admin
179 if ($this->isGranted('ROLE_ADMIN') && !empty($data['user'])) {
180 $user = $doctrine->getRepository(User
::class)->findOneById($data['user']);
184 $datetime = new \
DateTime('now');
186 //Set canceled time at start minus one day
187 $canceled = (clone $session->getStart())->sub(new \
DateInterval('P1D'));
191 'raincancel' => $form->has('raincancel') && $form->get('raincancel')->isClicked(),
192 'modify' => $form->has('modify') && $form->get('modify')->isClicked(),
193 'move' => $form->has('move') && $form->get('move')->isClicked(),
194 'cancel' => $form->has('cancel') && $form->get('cancel')->isClicked(),
195 'forcecancel' => $form->has('forcecancel') && $form->get('forcecancel')->isClicked(),
196 'attribute' => $form->has('attribute') && $form->get('attribute')->isClicked(),
197 'autoattribute' => $form->has('autoattribute') && $form->get('autoattribute')->isClicked(),
198 'lock' => $form->has('lock') && $form->get('lock')->isClicked(),
201 //With raincancel and application and (rainfall or admin)
202 if ($action['raincancel'] && ($application = $session->getApplication()) && ($session->getRainfall() >= 2 || $this->isGranted('ROLE_ADMIN'))) {
203 //Cancel application at start minus one day
204 $application->setCanceled($canceled);
207 $application->setUpdated($datetime);
209 //Insufficient rainfall
211 if ($session->getRainfall() < 2) {
213 //XXX: magic cheat score 42
214 $application->setScore(42);
217 //Queue application save
218 $manager->persist($application);
220 //Add notice in flash message
221 $this->addFlash('notice', $this->translator
->trans('Application %id% updated', ['%id%' => $application->getId()]));
224 $session->setUpdated($datetime);
227 $manager->persist($session);
229 //Add notice in flash message
230 $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id]));
232 } elseif ($action['modify']) {
234 if ($this->isGranted('ROLE_ADMIN')) {
236 $session->setDate($data['date']);
240 $session->setBegin($data['begin']);
243 $session->setLength($data['length']);
246 $session->setUpdated($datetime);
249 $manager->persist($session);
251 //Add notice in flash message
252 $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id]));
254 } elseif ($action['move']) {
256 $session->setLocation($doctrine->getRepository(Location
::class)->findOneById($data['location']));
259 $session->setUpdated($datetime);
262 $manager->persist($session);
264 //Add notice in flash message
265 $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id]));
266 //With cancel or forcecancel
267 } elseif ($action['cancel'] || $action['forcecancel']) {
269 $application = $doctrine->getRepository(Application
::class)->findOneBySessionUser($session, $user);
271 //Not already canceled
272 if ($application->getCanceled() === null) {
274 $application->setCanceled($datetime);
276 //Check if application is session application and (canceled 24h before start or forcecancel (as admin))
277 #if ($session->getApplication() == $application && ($datetime < $canceled || $action['forcecancel'])) {
278 if ($session->getApplication() == $application && $action['forcecancel']) {
280 //XXX: magic cheat score 42
281 $application->setScore(42);
283 //Unattribute session
284 $session->setApplication(null);
287 $session->setUpdated($datetime);
290 $manager->persist($session);
292 //Add notice in flash message
293 $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id]));
297 //Uncancel application
298 $application->setCanceled(null);
302 $application->setUpdated($datetime);
304 //Queue application save
305 $manager->persist($application);
307 //Add notice in flash message
308 $this->addFlash('notice', $this->translator
->trans('Application %id% updated', ['%id%' => $application->getId()]));
310 } elseif ($action['attribute']) {
312 $application = $doctrine->getRepository(Application
::class)->findOneBySessionUser($session, $user);
315 if ($application->getCanceled() !== null) {
316 //Uncancel application
317 $application->setCanceled(null);
321 //XXX: magic cheat score 42
322 $application->setScore(42);
325 $application->setUpdated($datetime);
327 //Queue application save
328 $manager->persist($application);
330 //Add notice in flash message
331 $this->addFlash('notice', $this->translator
->trans('Application %id% updated', ['%id%' => $application->getId()]));
333 //Unattribute session
334 $session->setApplication($application);
337 $session->setUpdated($datetime);
340 $manager->persist($session);
342 //Add notice in flash message
343 $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id]));
345 } elseif ($action['autoattribute']) {
346 //Get best application
347 //XXX: best application may not issue result while grace time or bad behaviour
348 if (!empty($application = $doctrine->getRepository(Session
::class)->findBestApplicationById($id))) {
350 $session->setApplication($application);
353 $session->setUpdated($datetime);
356 $manager->persist($session);
358 //Add notice in flash message
359 $this->addFlash('notice', $this->translator
->trans('Session %id% auto attributed', ['%id%' => $id]));
362 //Add warning in flash message
363 $this->addFlash('warning', $this->translator
->trans('Session %id% not auto attributed', ['%id%' => $id]));
366 } elseif ($action['lock']) {
368 if ($session->getLocked() !== null) {
373 $session->setLocked(null);
377 if ($application = $session->getApplication()) {
379 //XXX: magic cheat score 42
380 $application->setScore(42);
383 $application->setUpdated($datetime);
385 //Queue application save
386 $manager->persist($application);
388 //Add notice in flash message
389 $this->addFlash('notice', $this->translator
->trans('Application %id% updated', ['%id%' => $application->getId()]));
392 //Unattribute session
393 $session->setApplication(null);
396 $session->setLocked($datetime);
400 $session->setUpdated($datetime);
403 $manager->persist($session);
405 //Add notice in flash message
406 $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id]));
409 //Add warning in flash message
410 $this->addFlash('warning', $this->translator
->trans('Session %id% not updated', ['%id%' => $id]));
413 //Flush to get the ids
416 //Extract and process referer
417 if ($referer = $request->headers
->get('referer')) {
418 //Create referer request instance
419 $req = Request
::create($referer);
422 $path = $req->getPathInfo();
424 //Get referer query string
425 $query = $req->getQueryString();
428 $path = str_replace($request->getScriptName(), '', $path);
430 //Try with referer path
433 $oldContext = $this->router
->getContext();
435 //Force clean context
436 //XXX: prevent MethodNotAllowedException because current context method is POST in onevendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php+42
437 $this->router
->setContext(new RequestContext());
439 //Retrieve route matching path
440 $route = $this->router
->match($path);
443 $this->router
->setContext($oldContext);
449 $name = $route['_route'];
451 //Remove route and controller from route defaults
452 unset($route['_route'], $route['_controller']);
455 return $this->redirectToRoute($name, $route);
457 } catch(MethodNotAllowedException
|ResourceNotFoundException
$e) {
458 //Unset referer to fallback to default route
463 //Redirect to cleanup the form
464 return $this->redirectToRoute('rapsys_air_session_view', ['id' => $id]);
470 * @desc Display all sessions with an application or login form
472 * @param Request $request The request instance
474 * @return Response The rendered view
476 public function index(Request
$request): Response
{
478 $doctrine = $this->getDoctrine();
481 $section = $this->translator
->trans('Sessions');
484 $this->context
['description'] = $this->translator
->trans('Libre Air session list');
487 $this->context
['keywords'] = [
488 $this->translator
->trans('sessions'),
489 $this->translator
->trans('session list'),
490 $this->translator
->trans('listing'),
491 $this->translator
->trans('Libre Air')
495 $title = $this->translator
->trans($this->config
['site']['title']).' - '.$section;
498 $period = new \
DatePeriod(
499 //Start from first monday of week
500 new \
DateTime('Monday this week'),
501 //Iterate on each day
502 new \
DateInterval('P1D'),
503 //End with next sunday and 4 weeks
505 $this->isGranted('IS_AUTHENTICATED_REMEMBERED')?'Monday this week + 3 week':'Monday this week + 2 week'
510 //TODO: highlight with current session route parameter
511 $calendar = $doctrine->getRepository(Session
::class)->fetchCalendarByDatePeriod($this->translator
, $period, null, $request->get('session'), !$this->isGranted('IS_AUTHENTICATED_REMEMBERED'), $request->getLocale());
514 //XXX: we want to display all active locations anyway
515 $locations = $doctrine->getRepository(Location
::class)->findTranslatedSortedByPeriod($this->translator
, $period);
518 return $this->render('@RapsysAir/session/index.html.twig', ['title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+
$this->context
);
522 * List all sessions for tango argentin
524 * @desc Display all sessions in tango argentin json format
526 * @todo Drop it if unused by tangoargentin ???
528 * @param Request $request The request instance
530 * @return Response The rendered view or redirection
532 public function tangoargentin(Request
$request): Response
{
534 $doctrine = $this->getDoctrine();
537 $period = new \
DatePeriod(
538 //Start from first monday of week
539 new \
DateTime('today'),
540 //Iterate on each day
541 new \
DateInterval('P1D'),
542 //End with next sunday and 4 weeks
543 new \
DateTime('+2 week')
546 //Retrieve events to update
547 $sessions = $doctrine->getRepository(Session
::class)->fetchAllByDatePeriod($period, $request->getLocale());
552 //Iterate on sessions
553 foreach($sessions as $sessionId => $session) {
555 $title = $session['au_pseudonym'].' '.$this->translator
->trans('at '.$session['l_title']);
557 //Use Transliterator if available
558 if (class_exists('Transliterator')) {
559 $trans = \Transliterator
::create('Any-Latin; Latin-ASCII; Upper()');
560 $title = $trans->transliterate($title);
562 $title = strtoupper($title);
566 $rate = 'Au chapeau';
569 if ($session['p_hat'] === null) {
574 if ($session['p_rate'] !== null) {
576 $rate = $session['p_rate'].' €';
581 if ($session['p_rate'] !== null) {
583 $rate .= ', idéalement '.$session['p_rate'].' €';
589 'start' => $session['start']->format(\DateTime
::ISO8601
),
590 'stop' => $session['start']->format(\DateTime
::ISO8601
),
592 'short' => $session['p_short'],
594 'location' => implode(' ', [$session['l_address'], $session['l_zipcode'], $session['l_city']]),
595 'status' => (empty($session['a_canceled']) && empty($session['locked']))?'confirmed':'cancelled',
596 'updated' => $session['updated']->format(\DateTime
::ISO8601
),
597 'organizer' => $session['au_forename'],
598 'source' => $this->router
->generate('rapsys_air_session_view', ['id' => $sessionId], UrlGeneratorInterface
::ABSOLUTE_URL
)
603 $response = new Response(json_encode($ret));
606 $response->headers
->set('Content-Type', 'application/json');
615 * @todo XXX: TODO: add <link rel="prev|next" for sessions or classes ? />
616 * @todo XXX: TODO: like described in: https://www.alsacreations.com/article/lire/1400-attribut-rel-relations.html#xnf-rel-attribute
617 * @todo XXX: TODO: or here: http://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions
619 * @desc Display session by id with an application or login form
621 * @param Request $request The request instance
622 * @param int $id The session id
624 * @return Response The rendered view
626 public function view(Request
$request, $id): Response
{
628 $doctrine = $this->getDoctrine();
631 $locale = $request->getLocale();
634 if (empty($session = $doctrine->getRepository(Session
::class)->fetchOneById($id, $locale))) {
635 throw $this->createNotFoundException($this->translator
->trans('Unable to find session: %id%', ['%id%' => $id]));
639 $response = new Response();
642 $response->setEtag(md5(serialize($session)));
645 if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
647 $response->setLastModified(new \
DateTime('-1 year'));
650 $response->setPrivate();
651 //Without logged user
653 //Extract applications updated
654 $session['sa_updated'] = array_map(function($v){return new \
DateTime($v
);}, explode("\n", $session['sa_updated']));
657 $lastModified = max(array_merge([$session['updated'], $session['l_updated'], $session['t_updated'], $session['p_updated']], $session['sa_updated']));
660 $response->setLastModified($lastModified);
663 $response->setPublic();
665 //Without role and modification
666 if ($response->isNotModified($request)) {
667 //Return 304 response
672 //Set localization date formater
673 $intl = new \
IntlDateFormatter($locale, \IntlDateFormatter
::GREGORIAN
, \IntlDateFormatter
::SHORT
);
676 $this->context
['section'] = $this->translator
->trans($session['l_title']);
679 $this->context
['description'] = $this->translator
->trans('Outdoor Argentine Tango session the %date%', [ '%date%' => $intl->format($session['start']) ]);
682 $this->context
['keywords'] = [
683 $this->translator
->trans('outdoor'),
684 $this->translator
->trans('Argentine Tango'),
687 //Set localization date formater
688 $intlDate = new \
IntlDateFormatter($locale, \IntlDateFormatter
::TRADITIONAL
, \IntlDateFormatter
::NONE
);
690 //Set localization time formater
691 $intlTime = new \
IntlDateFormatter($locale, \IntlDateFormatter
::NONE
, \IntlDateFormatter
::SHORT
);
694 $this->context
['facebook'] = [
696 $session['au_pseudonym'] => [
697 'font' => 'irishgrover',
700 ucfirst($intlDate->format($session['start']))."\n".$this->translator
->trans('From %start% to %stop%', ['%start%' => $intlTime->format($session['start']), '%stop%' => $intlTime->format($session['stop'])]) => [
703 $this->translator
->trans('at '.$session['l_title']) => [
705 'font' => 'labelleaurore',
709 'updated' => $session['updated']->format('U')
710 ]+
$this->context
['facebook'];
712 //With granted session
713 if (!empty($session['au_id'])) {
714 array_unshift($this->context
['keywords'], $session['au_pseudonym']);
718 $this->context
['title'] = $this->translator
->trans(!empty($session['au_id'])?'Session %id% by %pseudonym%':'Session %id%', ['%id%' => $id, '%pseudonym%' => $session['au_pseudonym']]);
721 $this->context
['facebook']['metas']['og:title'] = $this->context
['title'].' '.$this->translator
->trans('at '.$session['l_title']);
723 //Create application form for role_guest
724 if ($this->isGranted('ROLE_GUEST')) {
726 $now = new \
DateTime('now');
728 //Create SessionType form
729 $sessionForm = $this->createForm('Rapsys\AirBundle\Form\SessionType', null, [
731 'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]),
732 //Set the form attribute
733 'attr' => [ 'class' => 'col' ],
735 'admin' => $this->isGranted('ROLE_ADMIN'),
736 //Set default user to current
737 'user' => $this->getUser()->getId(),
739 'date' => $session['date'],
741 'begin' => $session['begin'],
743 'length' => $session['length'],
745 'raincancel' => ($this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id']) && $session['rainfall'] >= 2,
747 'cancel' => $this->isGranted('ROLE_ADMIN') || in_array($this->getUser()->getId(), explode("\n", $session['sau_id'])),
749 'modify' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_REGULAR'),
751 'move' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_SENIOR'),
753 'attribute' => $this->isGranted('ROLE_ADMIN') && $session['locked'] === null,
755 'session' => $session['id']
758 //Add form to context
759 $this->context
['forms']['session'] = $sessionForm->createView();
762 //Add session in context
763 $this->context
['session'] = [
765 'date' => $session['date'],
766 'begin' => $session['begin'],
767 'start' => $session['start'],
768 'length' => $session['length'],
769 'stop' => $session['stop'],
770 'rainfall' => $session['rainfall'] !== null ? $session['rainfall'].' mm' : $session['rainfall'],
771 'rainrisk' => $session['rainrisk'] !== null ? ($session['rainrisk']*100).' %' : $session['rainrisk'],
772 'realfeel' => $session['realfeel'] !== null ? $session['realfeel'].' °C' : $session['realfeel'],
773 'realfeelmin' => $session['realfeelmin'] !== null ? $session['realfeelmin'].' °C' : $session['realfeelmin'],
774 'realfeelmax' => $session['realfeelmax'] !== null ? $session['realfeelmax'].' °C' : $session['realfeelmax'],
775 'temperature' => $session['temperature'] !== null ? $session['temperature'].' °C' : $session['temperature'],
776 'temperaturemin' => $session['temperaturemin'] !== null ? $session['temperaturemin'].' °C' : $session['temperaturemin'],
777 'temperaturemax' => $session['temperaturemax'] !== null ? $session['temperaturemax'].' °C' : $session['temperaturemax'],
778 'locked' => $session['locked'],
779 'created' => $session['created'],
780 'updated' => $session['updated'],
781 'title' => $this->translator
->trans('Session %id%', ['%id%' => $id]),
782 'application' => null,
784 'id' => $session['l_id'],
785 'at' => $this->translator
->trans('at '.$session['l_title']),
786 'title' => $this->translator
->trans($session['l_title']),
787 'address' => $session['l_address'],
788 'zipcode' => $session['l_zipcode'],
789 'city' => $session['l_city'],
790 'latitude' => $session['l_latitude'],
791 'longitude' => $session['l_longitude']
794 'id' => $session['t_id'],
795 'title' => $this->translator
->trans($session['t_title'])
798 'id' => $session['p_id'],
799 'description' => $session['p_description'],
800 'class' => $session['p_class'],
801 'contact' => $session['p_contact'],
802 'donate' => $session['p_donate'],
803 'link' => $session['p_link'],
804 'profile' => $session['p_profile'],
805 'rate' => $session['p_rate'],
806 'hat' => $session['p_hat']
808 'applications' => null
812 if (!empty($session['a_id'])) {
813 $this->context
['session']['application'] = [
815 'id' => $session['au_id'],
816 'by' => $this->translator
->trans('by %pseudonym%', [ '%pseudonym%' => $session['au_pseudonym'] ]),
817 'title' => $session['au_pseudonym']
819 'id' => $session['a_id'],
820 'canceled' => $session['a_canceled'],
821 'title' => $this->translator
->trans('Application %id%', [ '%id%' => $session['a_id'] ]),
826 if (!empty($session['sa_id'])) {
827 //Extract applications id
828 $session['sa_id'] = explode("\n", $session['sa_id']);
829 //Extract applications score
830 //XXX: score may be null before grant or for bad behaviour, replace NULL with 'NULL' to avoid silent drop in mysql
831 $session['sa_score'] = array_map(function($v){return $v
==='NULL'?null:$v
;}, explode("\n", $session['sa_score']));
832 //Extract applications created
833 $session['sa_created'] = array_map(function($v){return new \
DateTime($v
);}, explode("\n", $session['sa_created']));
834 //Extract applications updated
835 //XXX: done earlied when computing last modified
836 #$session['sa_updated'] = array_map(function($v){return new \DateTime($v);}, explode("\n", $session['sa_updated']));
837 //Extract applications canceled
838 //XXX: canceled is null before cancelation, replace NULL with 'NULL' to avoid silent drop in mysql
839 $session['sa_canceled'] = array_map(function($v){return $v
==='NULL'?null:new \
DateTime($v
);}, explode("\n", $session['sa_canceled']));
841 //Extract applications user id
842 $session['sau_id'] = explode("\n", $session['sau_id']);
843 //Extract applications user pseudonym
844 $session['sau_pseudonym'] = explode("\n", $session['sau_pseudonym']);
847 $this->context
['session']['applications'] = [];
848 foreach($session['sa_id'] as $i => $sa_id) {
849 $this->context
['session']['applications'][$sa_id] = [
851 'score' => $session['sa_score'][$i],
852 'created' => $session['sa_created'][$i],
853 'updated' => $session['sa_updated'][$i],
854 'canceled' => $session['sa_canceled'][$i]
856 if (!empty($session['sau_id'][$i])) {
857 $this->context
['session']['applications'][$sa_id]['user'] = [
858 'id' => $session['sau_id'][$i],
859 'title' => $session['sau_pseudonym'][$i]
866 $period = new \
DatePeriod(
867 //Start from first monday of week
868 new \
DateTime('Monday this week'),
869 //Iterate on each day
870 new \
DateInterval('P1D'),
871 //End with next sunday and 4 weeks
873 $this->isGranted('IS_AUTHENTICATED_REMEMBERED')?'Monday this week + 3 week':'Monday this week + 2 week'
878 //XXX: we want to display all active locations anyway
879 $locations = $doctrine->getRepository(Location
::class)->findTranslatedSortedByPeriod($this->translator
, $period, $session['au_id']);
882 return $this->render('@RapsysAir/session/view.html.twig', ['locations' => $locations]+
$this->context
, $response);