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.
This commit is contained in:
Kumi 2024-09-23 10:07:31 +02:00
parent 6cbe774d79
commit 9066e451c3
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -3,6 +3,8 @@
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once(dirname(__FILE__) . '/lib.php'); require_once(dirname(__FILE__) . '/lib.php');
require_once($CFG->libdir . '/completionlib.php');
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
$cm = get_coursemodule_from_id('exp360', $id, 0, false, MUST_EXIST); $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; $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);
}
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>