Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atypical completion behavior #102

Open
wants to merge 2 commits into
base: MOODLE_404_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions classes/completion/custom_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ public function get_state(string $rule): int {

if (empty($subcourse->completioncourse)) {
// The rule not enabled, return early.
return $type;
return COMPLETION_INCOMPLETE;
}

if (empty($subcourse->refcourse)) {
// Misconfigured subcourse instance, behave as if was not enabled.
return $type;
return COMPLETION_INCOMPLETE;
}

// Check if the referenced course is completed.
$coursecompletion = new \completion_completion(['userid' => $this->userid, 'course' => $subcourse->refcourse]);

return $coursecompletion->is_complete();
return $coursecompletion->is_complete()? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
}

/**
Expand All @@ -78,6 +78,11 @@ public function get_custom_rule_descriptions(): array {
* @return array
*/
public function get_sort_order(): array {
return ['completioncourse'];
return [
'completionview',
'completionusegrade',
'completionpassgrade',
'completioncourse'
];
}
}
8 changes: 7 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ function subcourse_get_coursemodule_info($coursemodule) {
global $CFG, $DB;

$subcourse = $DB->get_record('subcourse', ['id' => $coursemodule->instance],
'id, name, intro, introformat, instantredirect, blankwindow, coursepageprintgrade, coursepageprintprogress');
'id, name, intro, introformat, instantredirect, blankwindow, coursepageprintgrade, coursepageprintprogress, completioncourse');

if (!$subcourse) {
return null;
Expand All @@ -387,6 +387,12 @@ function subcourse_get_coursemodule_info($coursemodule) {
$info->content = format_module_intro('subcourse', $subcourse, $coursemodule->id, false);
}

// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$info->customdata->customcompletionrules['completioncourse'] = $subcourse->completioncourse;
}


return $info;
}

Expand Down