Example #1
0
 /**
  * Show planned games
  * @param int $date	Optional date in dd-mm-yyyy format to show only games for that date
  */
 public function showCalendar($date = null)
 {
     if ($date) {
         list($day, $month, $year) = explode('-', $date);
         if (!($day && $month && $year) || !checkdate($month, $day, $year)) {
             $this->redirect('/agenda');
         } else {
             // Valid date
             $day = str_pad($day, 2, '0', STR_PAD_LEFT);
             $month = str_pad($month, 2, '0', STR_PAD_LEFT);
             $year = str_pad($year, 2, '0', STR_PAD_LEFT);
             $formattedDate = $day . '-' . $month . '-' . $year;
             // Only one format allowed
             if ($date != $formattedDate) {
                 $this->redirect('/agenda/' . $formattedDate);
             }
             $date = $year . '-' . $month . '-' . $day;
             $this->path = '/' . $formattedDate;
         }
     } else {
         $this->path = '/index';
     }
     $this->subdirectory = '/agenda';
     $this->template = '/calendar/calendar.tpl';
     if ($this->getClearRender()) {
         $plannedGames = Calendar::getPlannedGames(Season::getInstance(), null, $date);
         $plannedEvents = Event::getPlannedEvents($date);
         // Don't accept dates without any games or events
         if ($date && !(count($plannedGames) || count($plannedEvents))) {
             $this->redirect('/agenda');
         }
         $sortedCalendar = array();
         foreach ($plannedGames as $oGame) {
             if (!isset($sortedCalendar[$oGame->date])) {
                 $sortedCalendar[$oGame->date] = array('events' => array(), 'games' => array());
             }
             $sortedCalendar[$oGame->date]['games'][] = $oGame;
         }
         foreach ($plannedEvents as $oEvent) {
             if (!isset($sortedCalendar[$oEvent->date])) {
                 $sortedCalendar[$oEvent->date] = array('events' => array(), 'games' => array());
                 $sortedCalendar[$oEvent->date]['events'][] = $oEvent;
             }
         }
         ksort($sortedCalendar);
         $this->assign('plannedEvents', $plannedEvents);
         $this->assign('plannedGames', $plannedGames);
         $this->assign('sortedCalendar', $sortedCalendar);
         $this->assign('calendarDate', $date);
     }
     $this->showOutput();
 }