Merge branch 'MDL-58388-master' of https://github.com/abias/moodle
authorDamyon Wiese <damyon@moodle.com>
Thu, 19 Oct 2017 04:47:18 +0000 (12:47 +0800)
committerDamyon Wiese <damyon@moodle.com>
Thu, 19 Oct 2017 04:47:18 +0000 (12:47 +0800)
admin/settings/courses.php
admin/tool/uploadcourse/classes/step2_form.php
course/format/lib.php
lang/en/moodle.php

index 5f83df7..64ef150 100644 (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));
 
index d3c5024..abdb88a 100644 (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);
+        }
     }
 
     /**
index a895b53..0e1e23e 100644 (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;
index b83e19f..9ecb714 100644 (file)
@@ -994,6 +994,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}';