MDL-79726 completion: Overall should consider pass/fail states too
In MDL-78744, when the overallcompletion state was added to be displayed in the activity card, only COMPLETE/INCOMPLETE status were considered. However, depending on the activity completion settings, there are a couple of states more that should also be included (COMPLETE_FAIL and COMPLETE_PASS). A new method has been added to the cm_completion_details class to calculate whether a module should be considered or not completed, based on their completion options and the current value for the overall complete state.
This commit is contained in:
@@ -193,6 +193,32 @@ class cm_completion_details {
|
||||
return (int)$this->completiondata->completionstate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the overall completion state of this course module should be marked as complete or not.
|
||||
* This is based on the completion settings of the course module, so when the course module requires a passing grade,
|
||||
* it will only be marked as complete when the user has passed the course module. Otherwise, it will be marked as complete
|
||||
* even when the user has failed the course module.
|
||||
*
|
||||
* @return bool True when the module can be marked as completed.
|
||||
*/
|
||||
public function is_overall_complete(): bool {
|
||||
$completionstates = [];
|
||||
if ($this->is_manual()) {
|
||||
$completionstates = [COMPLETION_COMPLETE];
|
||||
} else if ($this->is_automatic()) {
|
||||
// Successfull completion states depend on the completion settings.
|
||||
if (isset($this->completiondata->passgrade)) {
|
||||
// Passing grade is required. Don't mark it as complete when state is COMPLETION_COMPLETE_FAIL.
|
||||
$completionstates = [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS];
|
||||
} else {
|
||||
// Any grade is required. Mark it as complete even when state is COMPLETION_COMPLETE_FAIL.
|
||||
$completionstates = [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS, COMPLETION_COMPLETE_FAIL];
|
||||
}
|
||||
}
|
||||
|
||||
return in_array($this->get_overall_completion(), $completionstates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this activity module has completion enabled.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user