Skip to content

Commit

Permalink
Copy completion information related to grades too (#27)
Browse files Browse the repository at this point in the history
H5P activities with completion related to grades were not migrated
properly (only viewed completion was migrated as expected).
This patch should fix this bug.
  • Loading branch information
sarjona authored Jan 22, 2021
1 parent 801c531 commit 515db9c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ private static function create_mod_h5pactivity(stdClass $hvp, stdClass $hvpgrade
// Update couse_module information.
$h5pcm = self::add_course_module_to_section($hvpcm, $h5pactivity->cm->id);

// TODO: completion.
self::copy_tags($hvpcm, $h5pactivity);
self::copy_competencies($hvpcm, $h5pactivity);
self::copy_completion($hvpcm, $h5pactivity);
Expand Down Expand Up @@ -379,16 +378,17 @@ private static function copy_completion($hvpcm, $h5pactivity): void {
if ($completion->is_enabled($hvpcm)) {
$users = $completion->get_tracked_users();
foreach ($users as $user) {
$status = $completion->get_data($hvpcm, false, $user->id);
if ($status->viewed) {
$completion->set_module_viewed($h5pactivity->cm, $status->userid);
$data = $completion->get_data($hvpcm, false, $user->id);
if ($data->completionstate) {
// If the mod_hvp has completionstate higher than 0, create a completion status entry for mod_h5pactivity.
$data->id = 0;
$data->coursemoduleid = $h5pactivity->cm->id;
$completion->internal_set_data($h5pactivity->cm, $data);
}
$completion->update_state($h5pactivity->cm, $status->completionstate, $status->userid);
}
}
}


/**
* Helper function to create draft .h5p file from an existing mod_hvp activity.
*
Expand Down

0 comments on commit 515db9c

Please sign in to comment.