From 9066e451c3d2d344fb4db96ef9f508ec87c8620a Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 23 Sep 2024 10:07:31 +0200 Subject: [PATCH] feat: add completion tracking to view_content.php Integrated course module completion tracking to ensure activities are marked complete for users. This leverages the existing completionlib.php library to update the completion state. This enhancement ensures accurate tracking of user progress. --- view_content.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/view_content.php b/view_content.php index 7834b1d..4ffd4ae 100644 --- a/view_content.php +++ b/view_content.php @@ -3,6 +3,8 @@ require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); require_once(dirname(__FILE__) . '/lib.php'); +require_once($CFG->libdir . '/completionlib.php'); + $id = required_param('id', PARAM_INT); // Course Module ID $cm = get_coursemodule_from_id('exp360', $id, 0, false, MUST_EXIST); @@ -11,6 +13,14 @@ $exp360 = $DB->get_record('exp360', array('id' => $cm->instance), '*', MUST_EXIS $content_id = $exp360->content_id; +// Ensure completion is enabled for the course module. +$completion = new completion_info($course); + +if ($completion->is_enabled($cm)) { + // Mark the activity as completed for this user. + $completion->update_state($cm, COMPLETION_COMPLETE, $userId); +} + ?>