+ * @param Request $request The request instance
+ * @return Response The rendered view
+ */
+ public function cities(Request $request): Response {
+ //Add cities
+ $this->context['cities'] = $this->doctrine->getRepository(Location::class)->findCitiesAsArray($this->period, 0);
+
+ //Add dances
+ $this->context['dances'] = $this->doctrine->getRepository(Dance::class)->findNamesAsArray();
+
+ //Create response
+ $response = new Response();
+
+ //Set modified
+ $this->modified = max(array_map(function ($v) { return $v['modified']; }, array_merge($this->context['cities'], $this->context['dances'])));
+
+ //Add city multi
+ foreach($this->context['cities'] as $id => $city) {
+ //Add city multi
+ $this->context['cities'][$id]['multimap'] = $this->map->getMultiMap($city['multimap'], $this->modified->getTimestamp(), $city['locations']);
+ }
+
+ //With logged user
+ if ($this->checker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
+ //Set last modified
+ $response->setLastModified(new \DateTime('-1 year'));
+
+ //Set as private
+ $response->setPrivate();
+ //Without logged user
+ } else {
+ //Set etag
+ //XXX: only for public to force revalidation by last modified
+ $response->setEtag(md5(serialize(array_merge($this->context['cities'], $this->context['dances']))));
+
+ //Set last modified
+ $response->setLastModified($this->modified);
+
+ //Set as public
+ $response->setPublic();
+
+ //Without role and modification
+ if ($response->isNotModified($request)) {
+ //Return 304 response
+ return $response;
+ }
+ }
+
+ //Set section
+ $this->context['title']['page'] = $this->translator->trans('Libre Air cities');
+
+ //Set description
+ $this->context['description'] = $this->translator->trans('Libre Air city list');
+
+ //Set cities
+ $cities = array_map(function ($v) { return $v['in']; }, $this->context['cities']);
+
+ //Set dances
+ $dances = array_map(function ($v) { return $v['name']; }, $this->context['dances']);
+
+ //Set indoors
+ $indoors = array_reduce($this->context['cities'], function ($c, $v) { return array_merge($c, $v['indoors']); }, []);
+
+ //Set keywords
+ $this->context['keywords'] = array_values(
+ array_merge(
+ [
+ $this->translator->trans('Cities'),
+ $this->translator->trans('City list'),
+ $this->translator->trans('Listing'),
+ ],
+ $cities,
+ $indoors,
+ [
+ $this->translator->trans('calendar'),
+ $this->translator->trans('Libre Air')
+ ]
+ )
+ );
+
+ //Render the view
+ return $this->render('@RapsysAir/location/cities.html.twig', $this->context, $response);
+ }
+
+ /**
+ * Display city
+ *
+ * @todo XXX: TODO: add <link rel="prev|next" for sessions or classes ? />
+ * @todo XXX: TODO: like described in: https://www.alsacreations.com/article/lire/1400-attribut-rel-relations.html#xnf-rel-attribute
+ * @todo XXX: TODO: or here: http://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions
+ *
+ * @param Request $request The request instance
+ * @param float $latitude The city latitude
+ * @param float $longitude The city longitude
+ * @return Response The rendered view
+ */
+ public function city(Request $request, float $latitude, float $longitude, string $city): Response {
+ //Get city
+ if (!($this->context['city'] = $this->doctrine->getRepository(Location::class)->findCityByLatitudeLongitudeAsArray(floatval($latitude), floatval($longitude)))) {
+ throw $this->createNotFoundException($this->translator->trans('Unable to find city: %latitude%,%longitude%', ['%latitude%' => $latitude, '%longitude%' => $longitude]));
+ }
+
+ //Add calendar
+ $this->context['calendar'] = $this->doctrine->getRepository(Session::class)->findAllByPeriodAsCalendarArray($this->period, !$this->checker->isGranted('IS_AUTHENTICATED_REMEMBERED'), floatval($latitude), floatval($longitude));
+
+ //Set dances
+ $this->context['dances'] = [];
+
+ //Iterate on each calendar
+ foreach($this->context['calendar'] as $date => $calendar) {
+ //Iterate on each session
+ foreach($calendar['sessions'] as $sessionId => $session) {
+ //Session with application dance
+ if (!empty($session['application']['dance'])) {
+ //Add dance
+ $this->context['dances'][$session['application']['dance']['id']] = $session['application']['dance'];
+ }
+ }
+ }
+
+ //Add locations
+ $this->context['locations'] = $this->doctrine->getRepository(Location::class)->findAllByLatitudeLongitudeAsArray(floatval($latitude), floatval($longitude), $this->period, 0);
+
+ //Set modified
+ //XXX: dance modified is already computed inside calendar modified
+ $this->modified = max(array_merge([$this->context['city']['updated']], array_map(function ($v) { return $v['modified']; }, array_merge($this->context['calendar'], $this->context['locations']))));
+
+ //Create response
+ $response = new Response();
+
+ //With logged user
+ if ($this->checker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
+ //Set last modified
+ $response->setLastModified(new \DateTime('-1 year'));
+
+ //Set as private
+ $response->setPrivate();
+ //Without logged user
+ } else {
+ //Set etag
+ //XXX: only for public to force revalidation by last modified
+ $response->setEtag(md5(serialize(array_merge($this->context['city'], $this->context['dances'], $this->context['calendar'], $this->context['locations']))));
+
+ //Set last modified
+ $response->setLastModified($this->modified);
+
+ //Set as public
+ $response->setPublic();
+
+ //Without role and modification
+ if ($response->isNotModified($request)) {
+ //Return 304 response
+ return $response;
+ }
+ }
+
+ //Add multi
+ $this->context['multimap'] = $this->map->getMultiMap($this->context['city']['multimap'], $this->modified->getTimestamp(), $this->context['locations']);
+
+ //Set keywords
+ $this->context['keywords'] = [
+ $this->context['city']['city'],
+ $this->translator->trans('Indoor'),
+ $this->translator->trans('Outdoor'),
+ $this->translator->trans('Calendar'),
+ $this->translator->trans('Libre Air')
+ ];
+
+ //With context dances
+ if (!empty($this->context['dances'])) {
+ //Set dances
+ $dances = array_map(function ($v) { return $v['name']; }, $this->context['dances']);
+
+ //Insert dances in keywords
+ array_splice($this->context['keywords'], 1, 0, $dances);
+
+ //Get textual dances
+ $dances = implode($this->translator->trans(' and '), array_filter(array_merge([implode(', ', array_slice($dances, 0, -1))], array_slice($dances, -1)), 'strlen'));
+
+ //Set title
+ $this->context['title']['page'] = $this->translator->trans('%dances% %city%', ['%dances%' => $dances, '%city%' => $this->context['city']['in']]);
+
+ //Set description
+ $this->context['description'] = $this->translator->trans('%dances% indoor and outdoor calendar %city%', ['%dances%' => $dances, '%city%' => $this->context['city']['in']]);
+ } else {
+ //Set title
+ $this->context['title']['page'] = $this->translator->trans('Dance %city%', ['%city%' => $this->context['city']['in']]);
+
+ //Set description
+ $this->context['description'] = $this->translator->trans('Indoor and outdoor dance calendar %city%', ['%city%' => $this->context['city']['in']]);
+ }
+
+ //Set locations description
+ $this->context['locations_description'] = $this->translator->trans('Libre Air location list %city%', ['%city%' => $this->context['city']['in']]);
+
+ //Render the view
+ return $this->render('@RapsysAir/location/city.html.twig', $this->context, $response);
+ }
+
+ /**
+ * List all locations
+ *
+ * @desc Display all locations