diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php index 511fc93..0d03d5d 100644 --- a/classes/completion/custom_completion.php +++ b/classes/completion/custom_completion.php @@ -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; } /** @@ -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' + ]; } } diff --git a/lib.php b/lib.php index 4d780a3..2376047 100644 --- a/lib.php +++ b/lib.php @@ -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; @@ -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; }