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\HttpFoundation\Request
; 
  15 use Symfony\Component\HttpFoundation\Response
; 
  17 use Rapsys\AirBundle\Entity\Dance
; 
  19 class DanceController 
extends AbstractController 
{ 
  20         public function index(Request 
$request): Response 
{ 
  21                 throw new \
RuntimeException('TODO', 503); 
  22                 header('Content-Type: text/plain'); 
  31          * Display dance by name 
  33          * @todo XXX: TODO: add <link rel="prev|next" for dances ? /> 
  34          * @todo XXX: TODO: like described in: https://www.alsacreations.com/article/lire/1400-attribut-rel-relations.html#xnf-rel-attribute 
  35          * @todo XXX: TODO: or here: http://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions 
  37          * @TODO: faire plutôt comme /ville/x/y/paris 
  39          * @param Request $request The request instance 
  40          * @param string $name The shorted dance name 
  41          * @param string $dance The translated dance name 
  42          * @return Response The rendered view 
  44         public function name(Request 
$request, $name, $dance): Response 
{ 
  45                 throw new \
RuntimeException('TODO', 503); 
  48                 $name = $this->slugger
->unshort($sname = $name); 
  51                 if (empty($this->context
['dances'] = $this->doctrine
->getRepository(Dance
::class)->findByName($name))) { 
  53                         //XXX: prevent slugger reverse engineering by not displaying decoded name 
  54                         throw $this->createNotFoundException($this->translator
->trans('Unable to find dance %name%', ['%name%' => $sname])); 
  57                 header('Content-Type: text/plain'); 
  65                 if (!($this->context
['city'] = $this->doctrine
->getRepository(Location
::class)->findCityByLatitudeLongitudeAsArray(floatval($latitude), floatval($longitude)))) { 
  66                         throw $this->createNotFoundException($this->translator
->trans('Unable to find city: %latitude%,%longitude%', ['%latitude%' => $latitude, '%longitude%' => $longitude])); 
  70                 $this->context
['calendar'] = $this->doctrine
->getRepository(Session
::class)->findAllByPeriodAsCalendarArray($this->period
, !$this->checker
->isGranted('IS_AUTHENTICATED_REMEMBERED'), floatval($latitude), floatval($longitude)); 
  73                 $this->context
['dances'] = []; 
  75                 //Iterate on each calendar 
  76                 foreach($this->context
['calendar'] as $date => $calendar) { 
  77                         //Iterate on each session 
  78                         foreach($calendar['sessions'] as $sessionId => $session) { 
  79                                 //Session with application dance 
  80                                 if (!empty($session['application']['dance'])) { 
  82                                         $this->context
['dances'][$session['application']['dance']['id']] = $session['application']['dance']; 
  88                 $this->context
['locations'] = $this->doctrine
->getRepository(Location
::class)->findAllByLatitudeLongitudeAsArray(floatval($latitude), floatval($longitude), $this->period
); 
  91                 //XXX: dance modified is already computed inside calendar modified 
  92                 $this->modified 
= max(array_merge([$this->context
['city']['updated']], array_map(function ($v) { return $v
['modified']; }, array_merge($this->context
['calendar'], $this->context
['locations'])))); 
  95                 $response = new Response(); 
  98                 if ($this->checker
->isGranted('IS_AUTHENTICATED_REMEMBERED')) { 
 100                         $response->setLastModified(new \
DateTime('-1 year')); 
 103                         $response->setPrivate(); 
 104                 //Without logged user 
 107                         //XXX: only for public to force revalidation by last modified 
 108                         $response->setEtag(md5(serialize(array_merge($this->context
['city'], $this->context
['dances'], $this->context
['calendar'], $this->context
['locations'])))); 
 111                         $response->setLastModified($this->modified
); 
 114                         $response->setPublic(); 
 116                         //Without role and modification 
 117                         if ($response->isNotModified($request)) { 
 118                                 //Return 304 response 
 124                 #$this->context['osm'] = $this->osm->getMultiImage($this->context['city']['link'], $this->context['city']['osm'], $this->modified->getTimestamp(), $latitude, $longitude, $this->context['locations'], $this->osm->getMultiZoom($latitude, $longitude, $this->context['locations'], 16)); 
 125                 $this->context
['multimap'] = $this->map
->getMultiMap($this->context
['city']['multimap'], $this->modified
->getTimestamp(), $latitude, $longitude, $this->context
['locations'], $this->map
->getMultiZoom($latitude, $longitude, $this->context
['locations'])); 
 128                 $this->context
['keywords'] = [ 
 129                         $this->context
['city']['city'], 
 130                         $this->translator
->trans('Indoor'), 
 131                         $this->translator
->trans('Outdoor'), 
 132                         $this->translator
->trans('Calendar'), 
 133                         $this->translator
->trans('Libre Air') 
 136                 //With context dances 
 137                 if (!empty($this->context
['dances'])) { 
 139                         $dances = array_map(function ($v) { return $v
['name']; }, $this->context
['dances']); 
 141                         //Insert dances in keywords 
 142                         array_splice($this->context
['keywords'], 1, 0, $dances); 
 145                         $dances = implode($this->translator
->trans(' and '), array_filter(array_merge([implode(', ', array_slice($dances, 0, -1))], array_slice($dances, -1)), 'strlen')); 
 148                         $this->context
['title'] = $this->translator
->trans('%dances% %city%', ['%dances%' => $dances, '%city%' => $this->context
['city']['in']]); 
 151                         $this->context
['description'] = $this->translator
->trans('%dances% indoor and outdoor calendar %city%', ['%dances%' => $dances, '%city%' => $this->context
['city']['in']]); 
 154                         $this->context
['title'] = $this->translator
->trans('Dance %city%', ['%city%' => $this->context
['city']['in']]); 
 157                         $this->context
['description'] = $this->translator
->trans('Indoor and outdoor dance calendar %city%', ['%city%' => $this->context
['city']['in']]); 
 160                 //Set locations description 
 161                 $this->context
['locations_description'] = $this->translator
->trans('Libre Air location list %city%', ['%city%' => $this->context
['city']['in']]); 
 164                 return $this->render('@RapsysAir/dance/name.html.twig', $this->context
, $response); 
 167         public function view(Request 
$request, $id, $name, $type): Response 
{ 
 168                 throw new \
RuntimeException('TODO', 503); 
 169                 header('Content-Type: text/plain');