Date watcher
- Moodle 5.0–5.2
- 更新 2026-09-16
The Datewatch plugin allows other Moodle plugins to execute a callback every time some date occurs.
The Datewatch plugin allows other Moodle plugins to execute a callback every time some date occurs.
For example, plugins can monitor such things as “course enrolment ended”, “2 days before the due date”, etc.
To use, add this callback it in your plugin’s lib.php:
function YOURPLUGINNAME_datewatch() {
$watchers = [];
// Example 1: Send notification when course enrolment ended.
$watchers[] = tool_datewatchwatcher::instance(‘user_enrolments’, ‘timeend’)
->set_callback(function(tool_datewatchnotification $notification) {
if ($userenrolment = $notification->get_record()) {
$enrol = $notification->get_snapshot(‘enrol’, $userenrolment->enrolid);
YOURPLUGINNAME_send_notification_enrollment_ended($userenrolment->userid, $enrol->courseid);
}
});
// Example 2: Do something 3 days before assignment due date.
$watchers[] = tool_datewatchwatcher::instance(‘assign’, ‘duedate’, – 3 * DAYSECS)
->set_callback(function(tool_datewatchnotification $notification) {
// …
});
return $watchers;
- 5.0.10Moodle 5.0, 5.1, 5.2
- 4.5.4Moodle 3.9, 3.10, 3.11, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5