feat: add activity completion logic for courses
Introduced a new script to set activity completion for a user in a course. Ensures completion is enabled for the course module before marking activities as completed. This enhancement streamlines tracking of user progress within courses.
This commit is contained in:
parent
6ff596c5e1
commit
6cbe774d79
1 changed files with 24 additions and 0 deletions
24
completion.php
Normal file
24
completion.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
|
||||
function set_activity_completion($course, $cm, $userId) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$cmid = required_param('cmid', PARAM_INT);
|
||||
|
||||
$userid = $USER->id;
|
||||
|
||||
$course = get_course($courseid);
|
||||
$cm = get_coursemodule_from_id(null, $cmid);
|
||||
|
||||
set_activity_completion($course, $cm, $userid);
|
Loading…
Reference in a new issue