MDL-71370 course: Make showcompletionconditions nullable
* When completion tracking is not enabled for the course, it does not make sense for the course's showcompletionconditions setting to be set according to the default value indicated by the "moodlecourse | showcompletionconditions" admin setting. Setting showcompletionconditions as enabled when completion tracking is disabled makes even less sense. So in such a case, we should not be setting a default value for showcompletionconditions and allow it to be null. * When the course is edited and completion tracking is enabled, this also would set the "Show completion conditions" field to default to the value set in the "moodlecourse | showcompletionconditions" admin setting.
This commit is contained in:
@@ -2362,6 +2362,19 @@ function create_course($data, $editoroptions = NULL) {
|
||||
$data->summary_format = FORMAT_HTML;
|
||||
}
|
||||
|
||||
// Get default completion settings as a fallback in case the enablecompletion field is not set.
|
||||
$courseconfig = get_config('moodlecourse');
|
||||
$defaultcompletion = !empty($CFG->enablecompletion) ? $courseconfig->enablecompletion : COMPLETION_DISABLED;
|
||||
$enablecompletion = $data->enablecompletion ?? $defaultcompletion;
|
||||
// Unset showcompletionconditions when completion tracking is not enabled for the course.
|
||||
if ($enablecompletion == COMPLETION_DISABLED) {
|
||||
unset($data->showcompletionconditions);
|
||||
} else if (!isset($data->showcompletionconditions)) {
|
||||
// Show completion conditions should have a default value when completion is enabled. Set it to the site defaults.
|
||||
// This scenario can happen when a course is created through data generators or through a web service.
|
||||
$data->showcompletionconditions = $courseconfig->showcompletionconditions;
|
||||
}
|
||||
|
||||
if (!isset($data->visible)) {
|
||||
// data not from form, add missing visibility info
|
||||
$data->visible = $category->visible;
|
||||
@@ -2540,6 +2553,11 @@ function update_course($data, $editoroptions = NULL) {
|
||||
}
|
||||
}
|
||||
|
||||
// Set showcompletionconditions to null when completion tracking has been disabled for the course.
|
||||
if (isset($data->enablecompletion) && $data->enablecompletion == COMPLETION_DISABLED) {
|
||||
$data->showcompletionconditions = null;
|
||||
}
|
||||
|
||||
// Update custom fields if there are any of them in the form.
|
||||
$handler = core_course\customfield\course_handler::create();
|
||||
$handler->instance_form_save($data);
|
||||
|
||||
Reference in New Issue
Block a user