function showCalendar($slug, $date = null) { $date_begin = new DateTime($date); $date_begin->modify("first day of this month"); $date_begin->modify("-1 week"); $date_begin = $date_begin->format('Y-m-d'); $date_end = new DateTime($date); $date_end->modify("last day of this month"); $date_end->modify("+1 week"); $date_end = $date_end->format('Y-m-d'); $events = CalendarEvent::generateAllEventsBetween($date_begin, $date_end); $events_map = array(); foreach ($events as $event) { $events_map[$event->value][] = $event->getTitle(); } $calendar = new View(PLUGINS_ROOT . DS . CALENDAR_VIEWS . '/calendar_table', array('base_path' => BASE_URL . $slug, 'date' => $date, 'map' => $events_map)); $calendar->display(); }
/** * Shows a month calendar. * * @param string $slug slug of the calendar page, the slug becomes a base for links shown in the calendar * @param DateTime $date calendar shows this $date's month, null means "today"; the day of the month is ignored */ public static function showCalendar($slug, DateTime $date = null) { if (is_null($date)) { $date = new DateTime('now'); } $date_begin = clone $date; $date_begin->modify("first day of this month"); $date_begin->modify("-1 week"); $date_end = clone $date; $date_end->modify("last day of this month"); $date_end->modify("+1 week"); // generate events map $events = CalendarEvent::generateAllEventsBetween($date_begin, $date_end); $events_map = array(); foreach ($events as $event) { $events_map[$event->value][] = $event; } // display calendar table $view = new View(CALENDAR_VIEWS_FRONT . '/calendar', array('base_url' => get_url($slug), 'date' => $date, 'map' => $events_map)); $view->display(); }