MDL-58388 course: Add admin control for course end date default

This commit is contained in:
Alexander Bias 2017-09-29 14:25:31 +02:00
parent d8e9a23c48
commit 33a3ec7c93
4 changed files with 20 additions and 6 deletions

View File

@ -92,6 +92,9 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
$temp->add(new admin_setting_configselect('moodlecourse/coursedisplay', new lang_string('coursedisplay'),
new lang_string('coursedisplay_help'), COURSE_DISPLAY_SINGLEPAGE, $choices));
$temp->add(new admin_setting_configcheckbox('moodlecourse/courseenddateenabled', get_string('courseenddateenabled'),
get_string('courseenddateenabled_desc'), 1));
$temp->add(new admin_setting_configduration('moodlecourse/courseduration', get_string('courseduration'),
get_string('courseduration_desc'), YEARSECS));

View File

@ -212,9 +212,13 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
// The default end date depends on the course format.
$format = course_get_format((object)array('format' => get_config('moodlecourse', 'format')));
$enddate = $format->get_default_course_enddate($mform, array('startdate' => 'defaults[startdate]'));
// We add 1 day like we do above in startdate.
$mform->setDefault('defaults[enddate]', $enddate + 3600 * 24);
// Check if course end date form field should be enabled by default.
// If a default date is provided to the form element, it is magically enabled by default in the
// MoodleQuickForm_date_time_selector class, otherwise it's disabled by default.
if (get_config('moodlecourse', 'courseenddateenabled')) {
$enddate = $format->get_default_course_enddate($mform, array('startdate' => 'defaults[startdate]'));
$mform->setDefault('defaults[enddate]', $enddate);
}
}
/**

View File

@ -708,9 +708,14 @@ abstract class format_base {
}
if (!$forsection && empty($this->courseid)) {
// At this stage (this is called from definition_after_data) course data is already set as default.
// We can not overwrite what is in the database.
$mform->setDefault('enddate', $this->get_default_course_enddate($mform));
// Check if course end date form field should be enabled by default.
// If a default date is provided to the form element, it is magically enabled by default in the
// MoodleQuickForm_date_time_selector class, otherwise it's disabled by default.
if (get_config('moodlecourse', 'courseenddateenabled')) {
// At this stage (this is called from definition_after_data) course data is already set as default.
// We can not overwrite what is in the database.
$mform->setDefault('enddate', $this->get_default_course_enddate($mform));
}
}
return $elements;

View File

@ -986,6 +986,8 @@ $string['choosetheme'] = 'Choose theme';
$string['chooseuser'] = 'Choose a user';
$string['courseduration'] = 'Course duration';
$string['courseduration_desc'] = 'The course duration is used to calculate the default course end date. The course end date is only used for reports. Users can still enter the course after the end date.';
$string['courseenddateenabled'] = 'Course end date enabled by default';
$string['courseenddateenabled_desc'] = 'This setting determines if the course end date will be enabled by default for new courses and set to the date calculated from the course duration.';
$string['eventcontentviewed'] = 'Content viewed';
$string['filter'] = 'Filter';
$string['filteroption'] = '{$a->criteria}: {$a->value}';