3 namespace Rapsys\AirBundle\Controller
; 
   5 use Symfony\Component\Asset\Packages
; 
   6 use Symfony\Component\Filesystem\Exception\IOExceptionInterface
; 
   7 use Symfony\Component\Filesystem\Filesystem
; 
   8 use Symfony\Component\HttpFoundation\BinaryFileResponse
; 
   9 use Symfony\Component\HttpFoundation\Request
; 
  10 use Symfony\Component\HttpFoundation\Response
; 
  11 use Symfony\Component\Routing\Exception\MethodNotAllowedException
; 
  12 use Symfony\Component\Routing\Exception\ResourceNotFoundException
; 
  13 use Symfony\Component\Routing\Generator\UrlGeneratorInterface
; 
  14 use Symfony\Component\Routing\RequestContext
; 
  16 use Rapsys\AirBundle\Entity\Application
; 
  17 use Rapsys\AirBundle\Entity\User
; 
  18 use Rapsys\AirBundle\Entity\Slot
; 
  19 use Rapsys\AirBundle\Entity\Session
; 
  20 use Rapsys\AirBundle\Entity\Location
; 
  22 class SessionController 
extends DefaultController 
{ 
  26          * @desc Persist session and all required dependencies in database 
  28          * @param Request $request The request instance 
  30          * @return Response The rendered view or redirection 
  32          * @throws \RuntimeException When user has not at least guest role 
  34         public function edit(Request 
$request, $id): Response 
{ 
  35                 //Prevent non-guest to access here 
  36                 $this->denyAccessUnlessGranted('ROLE_GUEST', null, $this->translator
->trans('Unable to access this page without role %role%!', ['%role%' => $this->translator
->trans('Guest')])); 
  38                 //Reject non post requests 
  39                 if (!$request->isMethod('POST')) { 
  40                         throw new \
RuntimeException('Request method MUST be POST'); 
  44                 $doctrine = $this->getDoctrine(); 
  47                 $locale = $request->getLocale(); 
  50                 $session = $doctrine->getRepository(Session
::class)->fetchOneById($id, $locale); 
  55                         !$this->isGranted('ROLE_ADMIN') && 
  57                         $this->getUser()->getId() != $session['au_id'] && 
  58                         //or application without attributed user 
  59                         $session['au_id'] !== null && !in_array($this->getUser()->getId(), explode("\n", $session['sau_id'])) 
  61                         //Prevent non admin and non attributed user access 
  62                         throw $this->createAccessDeniedException(); 
  66                 $now = new \
DateTime('now'); 
  68                 //Create SessionType form 
  69                 $form = $this->createForm('Rapsys\AirBundle\Form\SessionType', null, [ 
  71                         'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]), 
  72                         //Set the form attribute 
  75                         'admin' => $this->isGranted('ROLE_ADMIN'), 
  76                         //Set default user to current 
  77                         'user' => $this->getUser()->getId(), 
  79                         'begin' => $session['begin'], 
  81                         'length' => $session['length'], 
  83                         'raincancel' => ($this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id']) && $session['rainfall'] >= 2, 
  85                         'cancel' => $this->isGranted('ROLE_ADMIN') || in_array($this->getUser()->getId(), explode("\n", $session['sau_id'])), 
  87                         'modify' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_REGULAR'), 
  89                         'move' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_SENIOR'), 
  91                         'attribute' => $this->isGranted('ROLE_ADMIN') && $session['locked'] === null, 
  93                         'session' => $session['id'] 
  96                 //Refill the fields in case of invalid form 
  97                 $form->handleRequest($request); 
 100                 #if (true) { $form->isValid(); 
 101                 //TODO: mettre une contrainte sur un des boutons submit, je sais pas encore comment 
 102                 if (!$form->isValid()) { 
 104                         $this->context
['page']['title'] = $this->translator
->trans(!empty($session['au_id'])?'Session %id% by %pseudonym%':'Session %id%', ['%id%' => $id, '%pseudonym%' => $session['au_pseudonym']]); 
 107                         $this->context
['ogps']['title'] = $this->context
['page']['title'].' '.$this->translator
->trans('at '.$session['l_title']); 
 110                         $this->context
['page']['section'] = $this->translator
->trans($session['l_title']); 
 112                         //Set localization date formater 
 113                         $intlDate = new \
IntlDateFormatter($locale, \IntlDateFormatter
::TRADITIONAL
, \IntlDateFormatter
::NONE
); 
 115                         //Set localization time formater 
 116                         $intlTime = new \
IntlDateFormatter($locale, \IntlDateFormatter
::NONE
, \IntlDateFormatter
::SHORT
); 
 119                         $this->context
['facebook'] +
= [ 
 121                                         $session['au_pseudonym'] => [ 
 122                                                 'font' => 'irishgrover', 
 125                                         ucfirst($intlDate->format($session['start']))."\n".$this->translator
->trans('From %start% to %stop%', ['%start%' => $intlTime->format($session['start']), '%stop%' => $intlTime->format($session['stop'])]) => [ 
 128                                         $this->translator
->trans('at '.$session['l_title']) => [ 
 130                                                 'font' => 'labelleaurore', 
 134                                 'updated' => $session['updated']->format('U') 
 137                         //Add session in context 
 138                         $this->context
['session'] = [ 
 140                                 'title' => $this->translator
->trans('Session %id%', ['%id%' => $id]), 
 142                                         'id' => $session['l_id'], 
 143                                         'at' => $this->translator
->trans('at '.$session['l_title']) 
 148                         return $this->render('@RapsysAir/session/edit.html.twig', ['form' => $form->createView()]+
$this->context
); 
 152                 $manager = $doctrine->getManager(); 
 155                 $data = $form->getData(); 
 158                 $session = $doctrine->getRepository(Session
::class)->findOneById($id); 
 161                 $user = $this->getUser(); 
 163                 //Replace with requested user for admin 
 164                 if ($this->isGranted('ROLE_ADMIN') && !empty($data['user'])) { 
 165                         $user = $doctrine->getRepository(User
::class)->findOneById($data['user']); 
 169                 $datetime = new \
DateTime('now'); 
 171                 //Set canceled time at start minus one day 
 172                 $canceled = (clone $session->getStart())->sub(new \
DateInterval('P1D')); 
 176                         'raincancel' => $form->has('raincancel') && $form->get('raincancel')->isClicked(), 
 177                         'modify' => $form->has('modify') && $form->get('modify')->isClicked(), 
 178                         'move' => $form->has('move') && $form->get('move')->isClicked(), 
 179                         'cancel' => $form->has('cancel') && $form->get('cancel')->isClicked(), 
 180                         'forcecancel' => $form->has('forcecancel') && $form->get('forcecancel')->isClicked(), 
 181                         'attribute' => $form->has('attribute') && $form->get('attribute')->isClicked(), 
 182                         'autoattribute' => $form->has('autoattribute') && $form->get('autoattribute')->isClicked(), 
 183                         'lock' => $form->has('lock') && $form->get('lock')->isClicked(), 
 186                 //With raincancel and application and (rainfall or admin) 
 187                 if ($action['raincancel'] && ($application = $session->getApplication()) && ($session->getRainfall() >= 2 || $this->isGranted('ROLE_ADMIN'))) { 
 188                         //Cancel application at start minus one day 
 189                         $application->setCanceled($canceled); 
 192                         $application->setUpdated($datetime); 
 194                         //Insufficient rainfall 
 196                         if ($session->getRainfall() < 2) { 
 198                                 //XXX: magic cheat score 42 
 199                                 $application->setScore(42); 
 202                         //Queue application save 
 203                         $manager->persist($application); 
 205                         //Add notice in flash message 
 206                         $this->addFlash('notice', $this->translator
->trans('Application %id% updated', ['%id%' => $application->getId()])); 
 209                         $session->setUpdated($datetime); 
 212                         $manager->persist($session); 
 214                         //Add notice in flash message 
 215                         $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id])); 
 217                 } elseif ($action['modify']) { 
 219                         $session->setBegin($data['begin']); 
 222                         $session->setLength($data['length']); 
 225                         $session->setUpdated($datetime); 
 228                         $manager->persist($session); 
 230                         //Add notice in flash message 
 231                         $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id])); 
 233                 } elseif ($action['move']) { 
 235                         $session->setLocation($doctrine->getRepository(Location
::class)->findOneById($data['location'])); 
 238                         $session->setUpdated($datetime); 
 241                         $manager->persist($session); 
 243                         //Add notice in flash message 
 244                         $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id])); 
 245                 //With cancel or forcecancel 
 246                 } elseif ($action['cancel'] || $action['forcecancel']) { 
 248                         $application = $doctrine->getRepository(Application
::class)->findOneBySessionUser($session, $user); 
 250                         //Not already canceled 
 251                         if ($application->getCanceled() === null) { 
 253                                 $application->setCanceled($datetime); 
 255                                 //Check if application is session application and (canceled 24h before start or forcecancel (as admin)) 
 256                                 #if ($session->getApplication() == $application && ($datetime < $canceled || $action['forcecancel'])) { 
 257                                 if ($session->getApplication() == $application && $action['forcecancel']) { 
 259                                         //XXX: magic cheat score 42 
 260                                         $application->setScore(42); 
 262                                         //Unattribute session 
 263                                         $session->setApplication(null); 
 266                                         $session->setUpdated($datetime); 
 269                                         $manager->persist($session); 
 271                                         //Add notice in flash message 
 272                                         $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id])); 
 276                                 //Uncancel application 
 277                                 $application->setCanceled(null); 
 281                         $application->setUpdated($datetime); 
 283                         //Queue application save 
 284                         $manager->persist($application); 
 286                         //Add notice in flash message 
 287                         $this->addFlash('notice', $this->translator
->trans('Application %id% updated', ['%id%' => $application->getId()])); 
 289                 } elseif ($action['attribute']) { 
 291                         $application = $doctrine->getRepository(Application
::class)->findOneBySessionUser($session, $user); 
 294                         if ($application->getCanceled() !== null) { 
 295                                 //Uncancel application 
 296                                 $application->setCanceled(null); 
 300                         //XXX: magic cheat score 42 
 301                         $application->setScore(42); 
 304                         $application->setUpdated($datetime); 
 306                         //Queue application save 
 307                         $manager->persist($application); 
 309                         //Add notice in flash message 
 310                         $this->addFlash('notice', $this->translator
->trans('Application %id% updated', ['%id%' => $application->getId()])); 
 312                         //Unattribute session 
 313                         $session->setApplication($application); 
 316                         $session->setUpdated($datetime); 
 319                         $manager->persist($session); 
 321                         //Add notice in flash message 
 322                         $this->addFlash('notice', $this->translator
->trans('Session %id% updated', ['%id%' => $id])); 
 324                 } elseif ($action['autoattribute']) { 
 325                         //Get best application 
 326                         //XXX: best application may not issue result while grace time or bad behaviour 
 327                         if (!empty($application = $doctrine->getRepository(Session
::class)->findBestApplicationById($id))) { 
 329                                 $session->setApplication($application); 
 332                                 $session->setUpdated($datetime); 
 335                                 $manager->persist($session); 
 337                                 //Add notice in flash message 
 338                                 $this->addFlash('notice', $this->translator
->trans('Session %id% auto attributed', ['%id%' => $id])); 
 341                                 //Add warning in flash message 
 342                                 $this->addFlash('warning', $this->translator
->trans('Session %id% not auto attributed', ['%id%' => $id])); 
 345                 } elseif ($action['lock']) { 
 347                         if ($session->getLocked() !== null) { 
 352                                 $session->setLocked(null); 
 356                                 if ($application = $session->getApplication()) { 
 358                                         //XXX: magic cheat score 42 
 359                                         $application->setScore(42); 
 362                                         $application->setUpdated($datetime); 
 364                                         //Queue application save 
 365                                         $manager->persist($application); 
 367                                         //Add notice in flash message 
 368                                         $this->addFlash('notice', $this->translator
->trans('Application %id% updated', ['%id%' => $application->getId()])); 
 371                                 //Unattribute session 
 372                                 $session->setApplication(null); 
 375                                 $session->setLocked($datetime); 
 379 #                       $applications = $doctrine->getRepository(Application::class)->findBySession($session); 
 382 #                       if (!empty($applications)) { 
 383 #                               //Iterate on each applications 
 384 #                               foreach($applications as $application) { 
 385 #                                       //Cancel application 
 386 #                                       $application->setCanceled($canceled); 
 389 #                                       $application->setUpdated($datetime); 
 391 #                                       //Queue application save 
 392 #                                       $manager->persist($application); 
 394 #                                       //Add notice in flash message 
 395 #                                       $this->addFlash('notice', $this->translator->trans('Application %id% updated', ['%id%' => $application->getId()])); 
 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')); 
 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_short']); 
 556                         //Use Transliterator if available 
 557                         if (class_exists('Transliterator')) { 
 558                                 $trans = \Transliterator
::create('Any-Latin; Latin-ASCII; Upper()'); 
 559                                 $title = $trans->transliterate($title); 
 561                                 $title = strtoupper($title); 
 565                                 'start' => $session['start']->format(\DateTime
::ISO8601
), 
 566                                 'stop' => $session['start']->format(\DateTime
::ISO8601
), 
 568                                 'short' => $session['p_short'], 
 569                                 'rate' => is_null($session['p_rate'])?'Au chapeau':$session['p_rate'].' euro'.($session['p_rate']>1?'s':''), 
 570                                 'location' => implode(' ', [$session['l_address'], $session['l_zipcode'], $session['l_city']]), 
 571                                 'status' => (empty($session['a_canceled']) && empty($session['locked']))?'confirmed':'cancelled', 
 572                                 'updated' => $session['updated']->format(\DateTime
::ISO8601
), 
 573                                 'organizer' => $session['au_forename'], 
 574                                 'website' => $this->router
->generate('rapsys_air_session_view', ['id' => $sessionId], UrlGeneratorInterface
::ABSOLUTE_URL
) 
 579                 $response = new Response(json_encode($ret)); 
 582                 $response->headers
->set('Content-Type', 'application/json'); 
 591          * @todo XXX: TODO: add <link rel="prev|next" for sessions or classes ? /> 
 592          * @todo XXX: TODO: like described in: https://www.alsacreations.com/article/lire/1400-attribut-rel-relations.html#xnf-rel-attribute 
 593          * @todo XXX: TODO: or here: http://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions 
 595          * @desc Display session by id with an application or login form 
 597          * @param Request $request The request instance 
 598          * @param int $id The session id 
 600          * @return Response The rendered view 
 602         public function view(Request 
$request, $id): Response 
{ 
 604                 $doctrine = $this->getDoctrine(); 
 607                 $locale = $request->getLocale(); 
 610                 if (empty($session = $doctrine->getRepository(Session
::class)->fetchOneById($id, $locale))) { 
 611                         throw $this->createNotFoundException($this->translator
->trans('Unable to find session: %id%', ['%id%' => $id])); 
 615                 $response = new Response(); 
 618                 $response->setEtag(md5(serialize($session))); 
 621                 if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { 
 623                         $response->setLastModified(new \
DateTime('-1 year')); 
 626                         $response->setPrivate(); 
 627                 //Without logged user 
 629                         //Extract applications updated 
 630                         $session['sa_updated'] = array_map(function($v){return new \
DateTime($v
);}, explode("\n", $session['sa_updated'])); 
 633                         $lastModified = max(array_merge([$session['updated'], $session['l_updated'], $session['t_updated'], $session['p_updated']], $session['sa_updated'])); 
 636                         $response->setLastModified($lastModified); 
 639                         $response->setPublic(); 
 641                         //Without role and modification 
 642                         if ($response->isNotModified($request)) { 
 643                                 //Return 304 response 
 648                 //Set localization date formater 
 649                 $intl = new \
IntlDateFormatter($locale, \IntlDateFormatter
::GREGORIAN
, \IntlDateFormatter
::SHORT
); 
 652                 $this->context
['page']['section'] = $this->translator
->trans($session['l_title']); 
 655                 $this->context
['page']['description'] = $this->translator
->trans('Outdoor Argentine Tango session the %date%', [ '%date%' => $intl->format($session['start']) ]); 
 658                 $this->context
['keywords'] = [ 
 659                         $this->translator
->trans('outdoor'), 
 660                         $this->translator
->trans('Argentine Tango'), 
 663                 //Set localization date formater 
 664                 $intlDate = new \
IntlDateFormatter($locale, \IntlDateFormatter
::TRADITIONAL
, \IntlDateFormatter
::NONE
); 
 666                 //Set localization time formater 
 667                 $intlTime = new \
IntlDateFormatter($locale, \IntlDateFormatter
::NONE
, \IntlDateFormatter
::SHORT
); 
 670                 $this->context
['facebook'] = [ 
 672                                 $session['au_pseudonym'] => [ 
 673                                         'font' => 'irishgrover', 
 676                                 ucfirst($intlDate->format($session['start']))."\n".$this->translator
->trans('From %start% to %stop%', ['%start%' => $intlTime->format($session['start']), '%stop%' => $intlTime->format($session['stop'])]) => [ 
 679                                 $this->translator
->trans('at '.$session['l_title']) => [ 
 681                                         'font' => 'labelleaurore', 
 685                         'updated' => $session['updated']->format('U') 
 686                 ]+
$this->context
['facebook']; 
 688                 //With granted session 
 689                 if (!empty($session['au_id'])) { 
 690                         $this->context
['keywords'][0] = $session['au_pseudonym']; 
 694                 $this->context
['page']['title'] = $this->translator
->trans(!empty($session['au_id'])?'Session %id% by %pseudonym%':'Session %id%', ['%id%' => $id, '%pseudonym%' => $session['au_pseudonym']]); 
 697                 $this->context
['ogps']['title'] = $this->context
['page']['title'].' '.$this->translator
->trans('at '.$session['l_title']); 
 699                 //Create application form for role_guest 
 700                 if ($this->isGranted('ROLE_GUEST')) { 
 701                         //Create ApplicationType form 
 702                         $applicationForm = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [ 
 704                                 'action' => $this->generateUrl('rapsys_air_application_add'), 
 705                                 //Set the form attribute 
 706                                 'attr' => [ 'class' => 'col' ], 
 708                                 'admin' => $this->isGranted('ROLE_ADMIN'), 
 709                                 //Set default user to current 
 710                                 'user' => $this->getUser()->getId(), 
 711                                 //Set default slot to current 
 712                                 'slot' => $this->getDoctrine()->getRepository(Slot
::class)->findOneById($session['t_id']), 
 713                                 //Set default location to current 
 714                                 'location' => $this->getDoctrine()->getRepository(Location
::class)->findOneById($session['l_id']), 
 717                         //Add form to context 
 718                         $this->context
['forms']['application'] = $applicationForm->createView(); 
 721                         $now = new \
DateTime('now'); 
 723                         //Create SessionType form 
 724                         $sessionForm = $this->createForm('Rapsys\AirBundle\Form\SessionType', null, [ 
 726                                 'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]), 
 727                                 //Set the form attribute 
 728                                 'attr' => [ 'class' => 'col' ], 
 730                                 'admin' => $this->isGranted('ROLE_ADMIN'), 
 731                                 //Set default user to current 
 732                                 'user' => $this->getUser()->getId(), 
 734                                 'begin' => $session['begin'], 
 736                                 'length' => $session['length'], 
 738                                 'raincancel' => ($this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id']) && $session['rainfall'] >= 2, 
 740                                 'cancel' => $this->isGranted('ROLE_ADMIN') || in_array($this->getUser()->getId(), explode("\n", $session['sau_id'])), 
 742                                 'modify' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_REGULAR'), 
 744                                 'move' => $this->isGranted('ROLE_ADMIN') || $this->getUser()->getId() == $session['au_id'] && $session['stop'] >= $now && $this->isGranted('ROLE_SENIOR'), 
 746                                 'attribute' => $this->isGranted('ROLE_ADMIN') && $session['locked'] === null, 
 748                                 'session' => $session['id'] 
 751                         //Add form to context 
 752                         $this->context
['forms']['session'] = $sessionForm->createView(); 
 755                 //Add session in context 
 756                 $this->context
['session'] = [ 
 758                         'date' => $session['date'], 
 759                         'begin' => $session['begin'], 
 760                         'start' => $session['start'], 
 761                         'length' => $session['length'], 
 762                         'stop' => $session['stop'], 
 763                         'rainfall' => $session['rainfall'] !== null ? $session['rainfall'].' mm' : $session['rainfall'], 
 764                         'rainrisk' => $session['rainrisk'] !== null ? ($session['rainrisk']*100).' %' : $session['rainrisk'], 
 765                         'realfeel' => $session['realfeel'] !== null ? $session['realfeel'].' °C' : $session['realfeel'], 
 766                         'realfeelmin' => $session['realfeelmin'] !== null ? $session['realfeelmin'].' °C' : $session['realfeelmin'], 
 767                         'realfeelmax' => $session['realfeelmax'] !== null ? $session['realfeelmax'].' °C' : $session['realfeelmax'], 
 768                         'temperature' => $session['temperature'] !== null ? $session['temperature'].' °C' : $session['temperature'], 
 769                         'temperaturemin' => $session['temperaturemin'] !== null ? $session['temperaturemin'].' °C' : $session['temperaturemin'], 
 770                         'temperaturemax' => $session['temperaturemax'] !== null ? $session['temperaturemax'].' °C' : $session['temperaturemax'], 
 771                         'locked' => $session['locked'], 
 772                         'created' => $session['created'], 
 773                         'updated' => $session['updated'], 
 774                         'title' => $this->translator
->trans('Session %id%', ['%id%' => $id]), 
 775                         'application' => null, 
 777                                 'id' => $session['l_id'], 
 778                                 'at' => $this->translator
->trans('at '.$session['l_title']), 
 779                                 'short' => $this->translator
->trans($session['l_short']), 
 780                                 'title' => $this->translator
->trans($session['l_title']), 
 781                                 'address' => $session['l_address'], 
 782                                 'zipcode' => $session['l_zipcode'], 
 783                                 'city' => $session['l_city'], 
 784                                 'latitude' => $session['l_latitude'], 
 785                                 'longitude' => $session['l_longitude'] 
 788                                 'id' => $session['t_id'], 
 789                                 'title' => $this->translator
->trans($session['t_title']) 
 792                                 'id' => $session['p_id'], 
 793                                 'description' => $session['p_description'], 
 794                                 'class' => $session['p_class'], 
 795                                 'contact' => $session['p_contact'], 
 796                                 'donate' => $session['p_donate'], 
 797                                 'link' => $session['p_link'], 
 798                                 'profile' => $session['p_profile'] 
 800                         'applications' => null 
 804                 if (!empty($session['a_id'])) { 
 805                         $this->context
['session']['application'] = [ 
 807                                         'id' => $session['au_id'], 
 808                                         'by' => $this->translator
->trans('by %pseudonym%', [ '%pseudonym%' => $session['au_pseudonym'] ]), 
 809                                         'title' => $session['au_pseudonym'] 
 811                                 'id' => $session['a_id'], 
 812                                 'canceled' => $session['a_canceled'], 
 813                                 'title' => $this->translator
->trans('Application %id%', [ '%id%' => $session['a_id'] ]), 
 818                 if (!empty($session['sa_id'])) { 
 819                         //Extract applications id 
 820                         $session['sa_id'] = explode("\n", $session['sa_id']); 
 821                         //Extract applications score 
 822                         //XXX: score may be null before grant or for bad behaviour, replace NULL with 'NULL' to avoid silent drop in mysql 
 823                         $session['sa_score'] = array_map(function($v){return $v
==='NULL'?null:$v
;}, explode("\n", $session['sa_score'])); 
 824                         //Extract applications created 
 825                         $session['sa_created'] = array_map(function($v){return new \
DateTime($v
);}, explode("\n", $session['sa_created'])); 
 826                         //Extract applications updated 
 827                         //XXX: done earlied when computing last modified 
 828                         #$session['sa_updated'] = array_map(function($v){return new \DateTime($v);}, explode("\n", $session['sa_updated'])); 
 829                         //Extract applications canceled 
 830                         //XXX: canceled is null before cancelation, replace NULL with 'NULL' to avoid silent drop in mysql 
 831                         $session['sa_canceled'] = array_map(function($v){return $v
==='NULL'?null:new \
DateTime($v
);}, explode("\n", $session['sa_canceled'])); 
 833                         //Extract applications user id 
 834                         $session['sau_id'] = explode("\n", $session['sau_id']); 
 835                         //Extract applications user pseudonym 
 836                         $session['sau_pseudonym'] = explode("\n", $session['sau_pseudonym']); 
 839                         $this->context
['session']['applications'] = []; 
 840                         foreach($session['sa_id'] as $i => $sa_id) { 
 841                                 $this->context
['session']['applications'][$sa_id] = [ 
 843                                         'score' => $session['sa_score'][$i], 
 844                                         'created' => $session['sa_created'][$i], 
 845                                         'updated' => $session['sa_updated'][$i], 
 846                                         'canceled' => $session['sa_canceled'][$i] 
 848                                 if (!empty($session['sau_id'][$i])) { 
 849                                         $this->context
['session']['applications'][$sa_id]['user'] = [ 
 850                                                 'id' => $session['sau_id'][$i], 
 851                                                 'title' => $session['sau_pseudonym'][$i] 
 858                 $period = new \
DatePeriod( 
 859                         //Start from first monday of week 
 860                         new \
DateTime('Monday this week'), 
 861                         //Iterate on each day 
 862                         new \
DateInterval('P1D'), 
 863                         //End with next sunday and 4 weeks 
 865                                 $this->isGranted('IS_AUTHENTICATED_REMEMBERED')?'Monday this week + 3 week':'Monday this week + 2 week' 
 870                 //XXX: we want to display all active locations anyway 
 871                 $locations = $doctrine->getRepository(Location
::class)->findTranslatedSortedByPeriod($this->translator
, $period, $session['au_id']); 
 874                 return $this->render('@RapsysAir/session/view.html.twig', ['locations' => $locations]+
$this->context
, $response);