feat: add course completion check functionality
Introduced a new observer to handle 'course_module_completion_updated' events, updating course completion status automatically. This streamlines the user experience by notifying users of their course completion status changes. Added observer registration to events configuration and updated the plugin version details.
This commit is contained in:
commit
4a7f631532
3 changed files with 40 additions and 0 deletions
25
classes/observer.php
Normal file
25
classes/observer.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace local_course_completion_checker;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
class observer
|
||||
{
|
||||
public static function check_course_completion(\core\event\course_module_completion_updated $event)
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$userid = $event->relateduserid;
|
||||
$courseid = $event->courseid;
|
||||
|
||||
$completion = new \completion_info($event->get_course());
|
||||
|
||||
if (!$completion->is_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$completion->update_state();
|
||||
\core\notification::add("Course completion status updated for user $userid in course $courseid.", \core\output\notification::NOTIFY_SUCCESS);
|
||||
}
|
||||
}
|
9
db/events.php
Normal file
9
db/events.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$observers = [
|
||||
[
|
||||
'eventname' => '\core\event\course_module_completion_updated',
|
||||
'callback' => 'local_course_completion_checker_observer::check_course_completion',
|
||||
],
|
||||
];
|
6
version.php
Normal file
6
version.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2024102100;
|
||||
$plugin->requires = 2021051700;
|
||||
$plugin->component = 'local_course_completion_checker';
|
Loading…
Reference in a new issue