- ->setParameter('end', $period->getEndDate())
- ->setParameter('uid', $userId)
- ->getResult();
-
- //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' => $this->translator->trans($date->format('l')).' '.$date->format('d'),
- 'class' => [],
- 'sessions' => []
- ];
-
- //Detect month change
- if ($month != $date->format('m')) {
- $month = $date->format('m');
- //Append month for first day of month
- //XXX: except if today to avoid double add
- if ($date->format('U') != strtotime('today')) {
- $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';
- }
-
- //Detect sunday
- if ($date->format('w') == 0) {
- $calendar[$Ymd]['class'][] = 'sunday';
- }
-
- //Iterate on each session to find the one of the day
- foreach($res as $session) {
- if (($sessionYmd = $session['date']->format('Ymd')) == $Ymd) {
- //Count number of application
- $count = count(explode("\n", $session['sau_id']));
-
- //Compute classes
- $class = [];
- if (!empty($session['a_id'])) {
- $applications = [ $session['au_id'] => $session['au_pseudonym'] ];
- if ($session['au_id'] == $userId) {
- $class[] = 'granted';
- } else {
- $class[] = 'disputed';
- }
- } elseif ($count > 1) {
- $class[] = 'disputed';
- } elseif (!empty($session['locked'])) {
- $class[] = 'locked';
- } else {
- $class[] = 'pending';
- }
-
- if ($sessionId == $session['id']) {
- $class[] = 'highlight';
- }
-
- //Set temperature
- //XXX: realfeel may be null, temperature should not
- $temperature = $session['realfeel'] !== null ? $session['realfeel'] : $session['temperature'];
-
- //Compute weather
- //XXX: rainfall may be null
- if ($session['rainrisk'] > 0.50 || $session['rainfall'] > 2) {
- $weather = self::GLYPHS['Stormy'];
- } elseif ($session['rainrisk'] > 0.40 || $session['rainfall'] > 1) {
- $weather = self::GLYPHS['Rainy'];
- } elseif ($temperature > 24) {
- $weather = self::GLYPHS['Cleary'];
- } elseif ($temperature > 17) {
- $weather = self::GLYPHS['Sunny'];
- } elseif ($temperature > 10) {
- $weather = self::GLYPHS['Cloudy'];
- } elseif ($temperature !== null) {
- $weather = self::GLYPHS['Winty'];
- } else {
- $weather = null;
- }
-
- //Init weathertitle
- $weathertitle = [];
-
- //Check if realfeel is available
- if ($session['realfeel'] !== null) {
- $weathertitle[] = $session['realfeel'].'°R';
- }
-
- //Check if temperature is available
- if ($session['temperature'] !== null) {
- $weathertitle[] = $session['temperature'].'°C';
- }
-
- //Check if rainrisk is available
- if ($session['rainrisk'] !== null) {
- $weathertitle[] = ($session['rainrisk']*100).'%';
- }
-
- //Check if rainfall is available
- if ($session['rainfall'] !== null) {
- $weathertitle[] = $session['rainfall'].'mm';
- }
-
- //Set applications
- $applications = [
- 0 => $this->translator->trans($session['t_title']).' '.$this->translator->trans('at '.$session['l_title']).$this->translator->trans(':')
- ];
-
- //Fetch pseudonyms from session applications
- $applications += array_combine(explode("\n", $session['sau_id']), array_map(function ($v) {return '- '.$v;}, explode("\n", $session['sau_pseudonym'])));
-
- //Set dance
- $dance = null;
-
- //Set pseudonym
- $pseudonym = null;
-
- //Check that session is not granted
- if (empty($session['a_id'])) {
- //With location id and unique application
- if ($count == 1) {
- //Set unique application pseudonym
- $pseudonym = $session['sau_pseudonym'];
- }
- //Session is granted
- } else {
- //Replace granted application
- $applications[$session['au_id']] = '* '.$session['au_pseudonym'];
-
- //Set dance
- $dance = $this->translator->trans($session['ad_name'].' '.lcfirst($session['ad_type']));
-
- //Set pseudonym
- $pseudonym = $session['au_pseudonym'].($count > 1 ? ' ['.$count.']':'');
- }
-
- //Set title
- $title = $this->translator->trans($session['l_title']).($count > 1 ? ' ['.$count.']':'');
-
- //Add the session
- $calendar[$Ymd]['sessions'][$session['t_id'].sprintf('%02d', $session['l_id'])] = [
- 'id' => $session['id'],
- 'start' => $session['start'],
- 'stop' => $session['stop'],
- 'location' => $this->translator->trans($session['l_title']),
- 'dance' => $dance,
- 'pseudonym' => $pseudonym,
- 'class' => $class,
- 'slot' => self::GLYPHS[$session['t_title']],
- 'slottitle' => $this->translator->trans($session['t_title']),
- 'weather' => $weather,
- 'weathertitle' => implode(' ', $weathertitle),
- 'applications' => $applications,
- 'rate' => $session['p_rate'],
- 'hat' => $session['p_hat']
- ];
- }
- }
-
- //Sort sessions
- ksort($calendar[$Ymd]['sessions']);
- }