+ //Fetch doctrine
+ $doctrine = $this->getDoctrine();
+
+ //Compute period
+ $period = new \DatePeriod(
+ //Start from first monday of week
+ new \DateTime('Monday this week'),
+ //Iterate on each day
+ new \DateInterval('P1D'),
+ //End with next sunday and 4 weeks
+ new \DateTime('Monday this week + 5 week')
+ );
+
+ //Fetch sessions
+ $sessions = $doctrine->getRepository(Session::class)->findAllByDatePeriod($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';
+ }
+
+ //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
+ ];
+ }
+ }
+
+ //Sort sessions
+ ksort($calendar[$Ymd]['sessions']);
+ }