-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add backport for core_cm_completion_details::is_overall_complete for …
…Moodle versions < 4.3
- Loading branch information
1 parent
35a3750
commit 57b9ea8
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace local_adler\local\backport; | ||
|
||
|
||
use core_completion\cm_completion_details as core_cm_completion_details; | ||
|
||
if (get_config('moodle', 'version') < 2023100900) { | ||
class backport_cm_completion_details extends core_cm_completion_details { | ||
/** | ||
* Backport from Moodle 4.4 for Moodle versions below 4.3 | ||
* | ||
* Whether this activity module instance tracks completion manually. | ||
* | ||
* @return bool | ||
*/ | ||
public function is_manual(): bool { | ||
return $this->cminfo->completion == COMPLETION_TRACKING_MANUAL; | ||
} | ||
|
||
/** | ||
* Backport from Moodle 4.4 for Moodle versions below 4.3 | ||
* | ||
* 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 (property_exists($this->completiondata, 'customcompletion') && !empty($this->completiondata->customcompletion)) { | ||
// If the module has any failed custom completion rule the state could be COMPLETION_COMPLETE_FAIL. | ||
$completionstates = [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS]; | ||
} else 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); | ||
} | ||
} | ||
} else { | ||
class backport_cm_completion_details extends core_cm_completion_details { | ||
} | ||
} |