mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-71288 completion: add fallback for plugins
This commits adds a fallback for plugins which does not have custom_completion implementation. For those cases, it will search for {modulename}_get_completion_state callback in the plugin and call get_overall_completion() method in cm_completion_details class to get the overall completion state for a course module and user.
This commit is contained in:
parent
0fd37bf5d8
commit
f518f61757
@ -116,21 +116,32 @@ class cm_completion_details {
|
||||
];
|
||||
}
|
||||
|
||||
// Custom completion rules.
|
||||
// Check if this activity has custom_completion class implemented.
|
||||
$cmcompletionclass = activity_custom_completion::get_cm_completion_class($this->cminfo->modname);
|
||||
if (!isset($completiondata->customcompletion) || !$cmcompletionclass) {
|
||||
// Return early if there are no custom rules to process or the cm completion class implementation is not available.
|
||||
return $details;
|
||||
if ($cmcompletionclass) {
|
||||
if (isset($completiondata->customcompletion)) {
|
||||
/** @var activity_custom_completion $cmcompletion */
|
||||
$cmcompletion = new $cmcompletionclass($this->cminfo, $this->userid);
|
||||
foreach ($completiondata->customcompletion as $rule => $status) {
|
||||
$details[$rule] = (object)[
|
||||
'status' => !$hasoverride ? $status : $completiondata->completionstate,
|
||||
'description' => $cmcompletion->get_custom_rule_description($rule),
|
||||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (function_exists($this->cminfo->modname . '_get_completion_state')) {
|
||||
// If the plugin does not have the custom completion implementation but implements the get_completion_state() callback,
|
||||
// fallback to displaying the overall completion state of the activity.
|
||||
$details = [
|
||||
'plugincompletionstate' => (object)[
|
||||
'status' => $this->get_overall_completion(),
|
||||
'description' => get_string('completeactivity', 'completion')
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/** @var activity_custom_completion $cmcompletion */
|
||||
$cmcompletion = new $cmcompletionclass($this->cminfo, $this->userid);
|
||||
foreach ($completiondata->customcompletion as $rule => $status) {
|
||||
$details[$rule] = (object)[
|
||||
'status' => !$hasoverride ? $status : $completiondata->completionstate,
|
||||
'description' => $cmcompletion->get_custom_rule_description($rule),
|
||||
];
|
||||
}
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ $string['checkall'] = 'Check or uncheck all activities and resources';
|
||||
$string['checkallsection'] = 'Check or uncheck all activities and resources in the following section: {$a}';
|
||||
$string['checkactivity'] = 'Checkbox for activity / resource: {$a}';
|
||||
$string['completed'] = 'Completed';
|
||||
$string['completeactivity'] = 'Complete the activity';
|
||||
$string['completedunlocked'] = 'Completion options unlocked';
|
||||
$string['completedunlockedtext'] = 'When you save changes, completion state for all students will be erased. If you change your mind about this, do not save the form.';
|
||||
$string['completedwarning'] = 'Completion options locked';
|
||||
|
Loading…
x
Reference in New Issue
Block a user