- //Fetch sessions
- $sessions = $doctrine->getRepository(Session::class)->findByDatePeriod($period);
-
- //Init calendar
- $calendar = [];
-
- //Init month
- $month = null;
-
- //Iterate on each day
- foreach($period as $date) {
- //Init day in calendar
- $calendar[$Ymd = $date->format('Ymd')] = [
- 'title' => $date->format('d'),
- 'class' => [],
- 'sessions' => []
- ];
- //Append month for first day of month
- if ($month != $date->format('m')) {
- $month = $date->format('m');
- $calendar[$Ymd]['title'] .= '/'.$month;
- }
- //Deal with today
- if ($date->format('U') == ($today = strtotime('today'))) {
- $calendar[$Ymd]['title'] .= '/'.$month;
- $calendar[$Ymd]['current'] = true;
- $calendar[$Ymd]['class'][] = 'current';
- }
- //Disable passed days
- if ($date->format('U') < $today) {
- $calendar[$Ymd]['disabled'] = true;
- $calendar[$Ymd]['class'][] = 'disabled';
- }
- //Set next month days
- if ($date->format('m') > date('m')) {
- $calendar[$Ymd]['next'] = true;
- $calendar[$Ymd]['class'][] = 'next';
- }
- //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';
- }
+ //Get textual cities
+ $cities = implode($this->translator->trans(' and '), array_filter(array_merge([implode(', ', array_slice($cities, 0, -1))], array_slice($cities, -1)), 'strlen'));
+
+ //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'] = $this->translator->trans('%dances% %cities%', ['%dances%' => $dances, '%cities%' => $cities]);
+
+ //Set description
+ //TODO: handle french translation when city start with a A, change à in en !
+ $this->context['description'] = $this->translator->trans('%dances% indoor and outdoor calendar %cities%', ['%dances%' => $dances, '%cities%' => $cities]);
+
+ //Set facebook type
+ //XXX: only valid for home page
+ $this->context['facebook']['metas']['og:type'] = 'website';
+
+ //Render the view
+ return $this->render('@RapsysAir/default/index.html.twig', $this->context, $response);
+ }
+
+ /**
+ * The organizer regulation page
+ *
+ * @desc Display the organizer regulation policy
+ *
+ * @param Request $request The request instance
+ * @return Response The rendered view
+ */
+ public function organizerRegulation(Request $request): Response {
+ //Set page
+ $this->context['title'] = $this->translator->trans('Organizer regulation');
+
+ //Set description
+ $this->context['description'] = $this->translator->trans('Libre Air organizer regulation');
+
+ //Set keywords
+ $this->context['keywords'] = [
+ $this->translator->trans('organizer regulation'),
+ $this->translator->trans('Libre Air')
+ ];
+
+ //Render template
+ $response = $this->render('@RapsysAir/default/organizer_regulation.html.twig', $this->context);
+
+ //Set as cachable
+ $response->setEtag(md5($response->getContent()));
+ $response->setPublic();
+ $response->isNotModified($request);
+
+ //Return response
+ return $response;
+ }
+
+ /**
+ * The terms of service page
+ *
+ * @desc Display the terms of service policy
+ *
+ * @param Request $request The request instance
+ * @return Response The rendered view
+ */
+ public function termsOfService(Request $request): Response {
+ //Set page
+ $this->context['title'] = $this->translator->trans('Terms of service');
+
+ //Set description
+ $this->context['description'] = $this->translator->trans('Libre Air terms of service');
+
+ //Set keywords
+ $this->context['keywords'] = [
+ $this->translator->trans('terms of service'),
+ $this->translator->trans('Libre Air')
+ ];
+
+ //Render template
+ $response = $this->render('@RapsysAir/default/terms_of_service.html.twig', $this->context);
+
+ //Set as cachable
+ $response->setEtag(md5($response->getContent()));
+ $response->setPublic();
+ $response->isNotModified($request);
+
+ //Return response
+ return $response;
+ }
+
+ /**
+ * The frequently asked questions page
+ *
+ * @desc Display the frequently asked questions
+ *
+ * @param Request $request The request instance
+ * @return Response The rendered view
+ */
+ public function frequentlyAskedQuestions(Request $request): Response {
+ //Set page
+ $this->context['title'] = $this->translator->trans('Frequently asked questions');
+
+ //Set description
+ $this->context['description'] = $this->translator->trans('Libre Air frequently asked questions');
+
+ //Set keywords
+ $this->context['keywords'] = [
+ $this->translator->trans('frequently asked questions'),
+ $this->translator->trans('faq'),
+ $this->translator->trans('Libre Air')
+ ];
+
+ //Render template
+ $response = $this->render('@RapsysAir/default/frequently_asked_questions.html.twig', $this->context);
+
+ //Set as cachable
+ $response->setEtag(md5($response->getContent()));
+ $response->setPublic();
+ $response->isNotModified($request);
+
+ //Return response
+ return $response;
+ }
+
+ /**
+ * List all users
+ *
+ * @desc Display all user with a group listed as users
+ *
+ * @param Request $request The request instance
+ *
+ * @return Response The rendered view
+ */
+ public function userIndex(Request $request): Response {
+ //With admin role
+ if ($this->isGranted('ROLE_ADMIN')) {
+ //Set section
+ $section = $this->translator->trans('Libre Air users');
+
+ //Set description
+ $this->context['description'] = $this->translator->trans('Libre Air user list');
+ //Without admin role
+ } else {
+ //Set section
+ $section = $this->translator->trans('Libre Air organizers');
+
+ //Set description
+ $this->context['description'] = $this->translator->trans('Libre Air organizers list');
+ }
+
+ //Set keywords
+ $this->context['keywords'] = [
+ $this->translator->trans('users'),
+ $this->translator->trans('user list'),
+ $this->translator->trans('listing'),
+ $this->translator->trans('Libre Air')
+ ];
+
+ //Set title
+ $title = $this->translator->trans($this->config['site']['title']).' - '.$section;
+
+ //Fetch users
+ $users = $this->doctrine->getRepository(User::class)->findIndexByGroupId();
+
+ //With admin role
+ if ($this->isGranted('ROLE_ADMIN')) {
+ //Display all users
+ $this->context['groups'] = $users;
+ //Without admin role
+ } else {
+ //Only display senior organizers
+ $this->context['users'] = $users[$this->translator->trans('Senior')];
+ }
+
+ //Render the view
+ return $this->render('@RapsysAir/user/index.html.twig', ['title' => $title, 'section' => $section]+$this->context);
+ }
+
+ /**
+ * List all sessions for the user
+ *
+ * @desc Display all sessions for the user with an application or login form
+ *
+ * @param Request $request The request instance
+ * @param int $id The user id
+ *
+ * @return Response The rendered view
+ */
+ public function userView(Request $request, int $id, ?string $user): Response {
+ //Get user
+ if (empty($this->context['user'] = $this->doctrine->getRepository(User::class)->findOneByIdAsArray($id, $this->locale))) {
+ //Throw not found
+ throw new NotFoundHttpException($this->translator->trans('Unable to find user: %id%', ['%id%' => $id]));
+ }
+
+ //Create token
+ $token = new AnonymousToken('', $this->context['user']['mail'], $this->context['user']['roles']);
+
+ //Prevent access when not admin, user is not guest and not currently logged user
+ if (!($isAdmin = $this->isGranted('ROLE_ADMIN')) && !($isGuest = $this->decision->decide($token, ['ROLE_GUEST']))) {
+ //Throw access denied
+ throw new AccessDeniedException($this->translator->trans('Unable to access user: %id%', ['%id%' => $id]));
+ }
+
+ //With invalid user slug
+ if ($this->context['user']['slug'] !== $user) {
+ //Redirect to cleaned url
+ return $this->redirectToRoute('rapsys_air_user_view', ['id' => $id, 'user' => $this->context['user']['slug']]);
+ }
+
+ //Fetch calendar
+ $this->context['calendar'] = $this->doctrine->getRepository(Session::class)->findAllByPeriodAsCalendarArray($this->period, !$this->isGranted('IS_AUTHENTICATED_REMEMBERED'), null, null, $id);
+
+ //Get locations at less than 2 km
+ $this->context['locations'] = $this->doctrine->getRepository(Location::class)->findAllByUserIdAsArray($id, $this->period, 2);
+
+ //Set ats
+ $ats = [];
+
+ //Set dances
+ $dances = [];
+
+ //Set indoors
+ $indoors = [];