- //Iterate on each session to find the one of the day
- foreach($sessions as $session) {
- if (($sessionYmd = $session->getDate()->format('Ymd')) == $Ymd) {
- //Count number of application
- $count = count($session->getApplications());
-
- //Compute classes
- $class = [];
- if ($session->getApplication()) {
- $class[] = 'granted';
- } elseif ($count == 0) {
- $class[] = 'orphaned';
- } elseif ($count > 1) {
- $class[] = 'disputed';
- } else {
- $class[] = 'pending';
- }
-
- //Add the session
- $calendar[$Ymd]['sessions'][$session->getSlot()->getId().$session->getLocation()->getId()] = [
- 'id' => $session->getId(),
- 'title' => ($count > 1?'['.$count.'] ':'').$session->getSlot()->getTitle().' '.$session->getLocation()->getTitle(),
- 'class' => $class
- ];
+ }
+
+ //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'];