插件管理工具稳定版

Date watcher

tool_datewatchMoodle Workplace plugins

  • 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;

返回插件目录