From 4a7f631532648e7b6189505d5fba4bf9ea3aa691 Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 21 Oct 2024 12:47:50 +0200 Subject: [PATCH] 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. --- classes/observer.php | 25 +++++++++++++++++++++++++ db/events.php | 9 +++++++++ version.php | 6 ++++++ 3 files changed, 40 insertions(+) create mode 100644 classes/observer.php create mode 100644 db/events.php create mode 100644 version.php diff --git a/classes/observer.php b/classes/observer.php new file mode 100644 index 0000000..ddb7a41 --- /dev/null +++ b/classes/observer.php @@ -0,0 +1,25 @@ +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); + } +} diff --git a/db/events.php b/db/events.php new file mode 100644 index 0000000..9f1407c --- /dev/null +++ b/db/events.php @@ -0,0 +1,9 @@ + '\core\event\course_module_completion_updated', + 'callback' => 'local_course_completion_checker_observer::check_course_completion', + ], +]; diff --git a/version.php b/version.php new file mode 100644 index 0000000..8ed2cc9 --- /dev/null +++ b/version.php @@ -0,0 +1,6 @@ +version = 2024102100; +$plugin->requires = 2021051700; +$plugin->component = 'local_course_completion_checker';