MDL-41792 core_calendar: refactored the calendar to allow the use of multiple calendar types

This commit is contained in:
Mark Nelson 2013-09-16 17:30:59 +08:00
parent bb74cdfef3
commit da3041379a
14 changed files with 759 additions and 475 deletions

View file

@ -46,26 +46,36 @@ require_once($CFG->dirroot.'/calendar/lib.php');
$courseid = optional_param('course', SITEID, PARAM_INT);
$view = optional_param('view', 'upcoming', PARAM_ALPHA);
$day = optional_param('cal_d', 0, PARAM_INT);
$mon = optional_param('cal_m', 0, PARAM_INT);
$yr = optional_param('cal_y', 0, PARAM_INT);
$day = optional_param('cal_d', 0, PARAM_INT);
$mon = optional_param('cal_m', 0, PARAM_INT);
$year = optional_param('cal_y', 0, PARAM_INT);
$time = optional_param('time', 0, PARAM_INT);
$url = new moodle_url('/calendar/view.php');
if ($courseid != SITEID) {
$url->param('course', $courseid);
}
if ($view !== 'upcoming') {
$url->param('view', $view);
}
if ($day !== 0) {
$url->param('cal_d', $day);
}
if ($mon !== 0) {
$url->param('cal_m', $mon);
}
if ($yr !== 0) {
$url->param('cal_y', $yr);
// If a day, month and year were passed then convert it to a timestamp. If these were passed
// then we can assume the day, month and year are passed as Gregorian, as no where in core
// should we be passing these values rather than the time. This is done for BC.
if (!empty($day) && !empty($mon) && !empty($year)) {
if (checkdate($mon, $day, $year)) {
$time = make_timestamp($year, $mon, $day);
} else {
$time = time();
}
} else if (empty($time)) {
$time = time();
}
$url->param('time', $time);
$PAGE->set_url($url);
if ($courseid != SITEID && !empty($courseid)) {
@ -78,23 +88,16 @@ if ($courseid != SITEID && !empty($courseid)) {
$courses = calendar_get_default_courses();
$issite = true;
}
require_course_login($course);
$calendar = new calendar_information($day, $mon, $yr);
$calendar = new calendar_information(0, 0, 0, $time);
$calendar->prepare_for_view($course, $courses);
$now = usergetdate(time());
$pagetitle = '';
$strcalendar = get_string('calendar', 'calendar');
if (!checkdate($mon, $day, $yr)) {
$day = intval($now['mday']);
$mon = intval($now['mon']);
$yr = intval($now['year']);
}
$time = make_timestamp($yr, $mon, $day);
switch($view) {
case 'day':
$PAGE->navbar->add(userdate($time, get_string('strftimedate')));