MDL-58102 course: Set sensible defaults for completion form fields

Part of MDL-55611 epic.
This commit is contained in:
Jun Pataleta
2017-04-03 11:37:08 +08:00
committed by Damyon Wiese
parent f8ffd1f249
commit a0a6762ec3
+13 -1
View File
@@ -628,6 +628,8 @@ abstract class moodleform_mod extends moodleform {
}
if ($completion->is_enabled()) {
$mform->addElement('header', 'activitycompletionheader', get_string('activitycompletion', 'completion'));
// With defaults being set, it would be better to expand this section so that the creator can customise when necessary.
$mform->setExpanded('activitycompletionheader');
// Unlock button for if people have completed it (will
// be removed in definition_after_data if they haven't)
@@ -639,7 +641,13 @@ abstract class moodleform_mod extends moodleform {
$trackingdefault = COMPLETION_TRACKING_NONE;
// If system and activity default is on, set it.
if ($CFG->completiondefault && $this->_features->defaultcompletion) {
$trackingdefault = COMPLETION_TRACKING_MANUAL;
$hasrules = plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_HAS_RULES, true);
$tracksviews = plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_TRACKS_VIEWS, true);
if ($hasrules || $tracksviews) {
$trackingdefault = COMPLETION_TRACKING_AUTOMATIC;
} else {
$trackingdefault = COMPLETION_TRACKING_MANUAL;
}
}
$mform->addElement('select', 'completion', get_string('completion', 'completion'),
@@ -654,6 +662,10 @@ abstract class moodleform_mod extends moodleform {
$mform->addElement('checkbox', 'completionview', get_string('completionview', 'completion'),
get_string('completionview_desc', 'completion'));
$mform->disabledIf('completionview', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
// Check by default if automatic completion tracking is set.
if ($trackingdefault == COMPLETION_TRACKING_AUTOMATIC) {
$mform->setDefault('completionview', 1);
}
$gotcompletionoptions = true;
}