Moodle Plugins directory: Date watcher | Moodle.org
Date watcher
Administration tools ::: tool_datewatch
Maintained by
Moodle Workplace
Part of set Moodle Workplace.
The Datewatch plugin allows other Moodle plugins to execute a callback every time some date occurs.
Latest release:
798 sites
154 downloads
14 fans
Current versions available: 2
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:
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_datewatch\watcher::instance('user_enrolments', 'timeend') ->set_callback(function(\tool_datewatch\notification $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_datewatch\watcher::instance('assign', 'duedate', - 3 * DAYSECS) ->set_callback(function(\tool_datewatch\notification $notification) { // ... }); return $watchers; }
There are two requirements to the watched dates:
- The watched date has to be a field in a database table plus/minus a fixed offset (i.e. "7 days before the due date");
- There must be events triggered every time a record is added, updated or deleted in the respective database table and this event must have correct `objecttable` and `objectid` properties.
This plugin has been contributed and is maintained by the Moodle Workplace team.
Useful links
Contributors
Moodle Workplace (Lead maintainer)
Please login to view contributors details and/or to contact them
Comments