Commit 41b7375c authored by Andrew Nicols's avatar Andrew Nicols
Browse files

MDL-60763 core_calendar: Deprecate calendar_get_upcoming

parent 9dead25f
......@@ -77,8 +77,15 @@ class block_calendar_upcoming extends block_base {
* @param \moodle_url|string $linkhref link to event referer
* @param boolean $showcourselink whether links to courses should be shown
* @return string|null $content html block content
* @deprecated since 3.4
*/
public static function get_upcoming_content($events, $linkhref = null, $showcourselink = false) {
debugging(
'get_upcoming_content() is deprecated. ' +
'Please see block_calendar_upcoming::get_content() for the correct API usage.',
DEBUG_DEVELOPER
);
$content = '';
$lines = count($events);
......
=== 3.4 ===
* block_calendar_upcoming::get_upcoming_content has been deprecated. Please
update your code to use the new APIs. You can see an example of how these
may be used in block_calendar_upcoming::get_content().
......@@ -1427,77 +1427,6 @@ function calendar_get_starting_weekday() {
return $calendartype->get_starting_weekday();
}
/**
* Gets the calendar upcoming event.
*
* @param array $courses array of courses
* @param array|int|bool $groups array of groups, group id or boolean for all/no group events
* @param array|int|bool $users array of users, user id or boolean for all/no user events
* @param int $daysinfuture number of days in the future we 'll look
* @param int $maxevents maximum number of events
* @param int $fromtime start time
* @return array $output array of upcoming events
*/
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) {
global $COURSE;
$display = new \stdClass;
$display->range = $daysinfuture; // How many days in the future we 'll look.
$display->maxevents = $maxevents;
$output = array();
$processed = 0;
$now = time(); // We 'll need this later.
$usermidnighttoday = usergetmidnight($now);
if ($fromtime) {
$display->tstart = $fromtime;
} else {
$display->tstart = $usermidnighttoday;
}
// This works correctly with respect to the user's DST, but it is accurate
// only because $fromtime is always the exact midnight of some day!
$display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1;
// Get the events matching our criteria.
$events = calendar_get_legacy_events($display->tstart, $display->tend, $users, $groups, $courses);
// This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
// possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
// will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra
// arguments to this function.
$hrefparams = array();
if (!empty($courses)) {
$courses = array_diff($courses, array(SITEID));
if (count($courses) == 1) {
$hrefparams['course'] = reset($courses);
}
}
if ($events !== false) {
foreach ($events as $event) {
if (!empty($event->modulename)) {
$instances = get_fast_modinfo($event->courseid)->get_instances_of($event->modulename);
if (empty($instances[$event->instance]->uservisible)) {
continue;
}
}
if ($processed >= $display->maxevents) {
break;
}
$event->time = calendar_format_event_time($event, $now, $hrefparams);
$output[] = $event;
$processed++;
}
}
return $output;
}
/**
* Get a HTML link to a course.
*
......
......@@ -2,8 +2,7 @@ This files describes API changes in /calendar/* ,
information provided here is intended especially for developers.
=== 3.4 ===
* calendar_get_mini has been deprecated. Please update to use the new
exporters and renderers.
* calendar_get_mini, and calendar_get_upcoming have been deprecated. Please update to use the new exporters and renderers.
* added core_calendar_get_valid_event_timestart_range and core_calendar_event_timestart_updated callbacks for module events
when the update_event_start_day function is used in the local api.
......
......@@ -6243,8 +6243,11 @@ function calendar_wday_name($englishname) {
function calendar_get_block_upcoming($events, $linkhref = null, $showcourselink = false) {
global $CFG;
debugging(__FUNCTION__ . '() is deprecated, please use block_calendar_upcoming::get_upcoming_content() instead.',
DEBUG_DEVELOPER);
debugging(
__FUNCTION__ . '() has been deprecated. ' +
'Please see block_calendar_upcoming::get_content() for the correct API usage.',
DEBUG_DEVELOPER
);
require_once($CFG->dirroot . '/blocks/moodleblock.class.php');
require_once($CFG->dirroot . '/blocks/calendar_upcoming/block_calendar_upcoming.php');
......@@ -6430,3 +6433,81 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
list($data, $template) = calendar_get_view($calendar, 'mini');
return $renderer->render_from_template($template, $data);
}
/**
* Gets the calendar upcoming event.
*
* @param array $courses array of courses
* @param array|int|bool $groups array of groups, group id or boolean for all/no group events
* @param array|int|bool $users array of users, user id or boolean for all/no user events
* @param int $daysinfuture number of days in the future we 'll look
* @param int $maxevents maximum number of events
* @param int $fromtime start time
* @return array $output array of upcoming events
* @deprecated since Moodle 3.4. MDL-59333
*/
function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) {
debugging(
'calendar_get_upcoming() has been deprecated. ' +
'Please see block_calendar_upcoming::get_content() for the correct API usage.',
DEBUG_DEVELOPER
);
global $COURSE;
$display = new \stdClass;
$display->range = $daysinfuture; // How many days in the future we 'll look.
$display->maxevents = $maxevents;
$output = array();
$processed = 0;
$now = time(); // We 'll need this later.
$usermidnighttoday = usergetmidnight($now);
if ($fromtime) {
$display->tstart = $fromtime;
} else {
$display->tstart = $usermidnighttoday;
}
// This works correctly with respect to the user's DST, but it is accurate
// only because $fromtime is always the exact midnight of some day!
$display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1;
// Get the events matching our criteria.
$events = calendar_get_legacy_events($display->tstart, $display->tend, $users, $groups, $courses);
// This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
// possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
// will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra
// arguments to this function.
$hrefparams = array();
if (!empty($courses)) {
$courses = array_diff($courses, array(SITEID));
if (count($courses) == 1) {
$hrefparams['course'] = reset($courses);
}
}
if ($events !== false) {
foreach ($events as $event) {
if (!empty($event->modulename)) {
$instances = get_fast_modinfo($event->courseid)->get_instances_of($event->modulename);
if (empty($instances[$event->instance]->uservisible)) {
continue;
}
}
if ($processed >= $display->maxevents) {
break;
}
$event->time = calendar_format_event_time($event, $now, $hrefparams);
$output[] = $event;
$processed++;
}
}
return $output;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment