Merge branch 'MDL-43648_m35v2' of https://github.com/sbourget/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 9 Jan 2018 03:43:33 +0000 (11:43 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 9 Jan 2018 03:43:33 +0000 (11:43 +0800)
admin/tool/uploadcourse/classes/step2_form.php
backup/moodle2/restore_course_task.class.php
backup/util/plan/restore_step.class.php
course/edit_form.php
course/reset_form.php
lib/form/amd/build/defaultcustom.min.js
lib/form/amd/src/defaultcustom.js
lib/form/defaultcustom.php

index abdb88a..2e39463 100644 (file)
@@ -93,11 +93,11 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
         $mform->addHelpButton('defaults[visible]', 'coursevisibility');
         $mform->setDefault('defaults[visible]', $courseconfig->visible);
 
-        $mform->addElement('date_selector', 'defaults[startdate]', get_string('startdate'));
+        $mform->addElement('date_time_selector', 'defaults[startdate]', get_string('startdate'));
         $mform->addHelpButton('defaults[startdate]', 'startdate');
         $mform->setDefault('defaults[startdate]', time() + 3600 * 24);
 
-        $mform->addElement('date_selector', 'defaults[enddate]', get_string('enddate'), array('optional' => true));
+        $mform->addElement('date_time_selector', 'defaults[enddate]', get_string('enddate'), array('optional' => true));
         $mform->addHelpButton('defaults[enddate]', 'enddate');
 
         $courseformats = get_sorted_course_formats(true);
index 2121c02..6bcf826 100644 (file)
@@ -200,7 +200,7 @@ class restore_course_task extends restore_task {
         $startdatedefaultvalue = $this->get_info()->original_course_startdate;
         $startdate = new restore_course_defaultcustom_setting('course_startdate', base_setting::IS_INTEGER, $startdatedefaultvalue);
         $startdate->set_ui(new backup_setting_ui_defaultcustom($startdate, get_string('setting_course_startdate', 'backup'),
-            ['customvalue' => $startdatedefaultvalue, 'defaultvalue' => $course->startdate, 'type' => 'date_selector']));
+            ['customvalue' => $startdatedefaultvalue, 'defaultvalue' => $course->startdate, 'type' => 'date_time_selector']));
         $this->add_setting($startdate);
 
         $keep_enrols = new restore_course_generic_setting('keep_roles_and_enrolments', base_setting::IS_BOOLEAN, false);
index 18e77ef..4890b6c 100644 (file)
@@ -84,10 +84,6 @@ abstract class restore_step extends base_step {
             // Original course has not startdate or setting doesn't exist, offset = 0.
             $cache[$this->get_restoreid()] = 0;
 
-        } else if (abs($setting - $original) < 24 * 60 * 60) {
-            // Less than 24h of difference, offset = 0 (this avoids some problems with timezones).
-            $cache[$this->get_restoreid()] = 0;
-
         } else {
             // Arrived here, let's calculate the real offset.
             $cache[$this->get_restoreid()] = $setting - $original;
index 47c8c18..4ffe172 100644 (file)
@@ -120,12 +120,13 @@ class course_edit_form extends moodleform {
                 $mform->setConstant('visible', $courseconfig->visible);
             }
         }
-
-        $mform->addElement('date_selector', 'startdate', get_string('startdate'));
+        $mform->addElement('date_time_selector', 'startdate', get_string('startdate'));
         $mform->addHelpButton('startdate', 'startdate');
-        $mform->setDefault('startdate', time() + 3600 * 24);
+        $date = (new DateTime())->setTimestamp(usergetmidnight(time()));
+        $date->modify('+1 day');
+        $mform->setDefault('startdate', $date->getTimestamp());
 
-        $mform->addElement('date_selector', 'enddate', get_string('enddate'), array('optional' => true));
+        $mform->addElement('date_time_selector', 'enddate', get_string('enddate'), array('optional' => true));
         $mform->addHelpButton('enddate', 'enddate');
 
         $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100"  size="10"');
index 6314a16..1accadd 100644 (file)
@@ -41,9 +41,9 @@ class course_reset_form extends moodleform {
 
         $mform->addElement('header', 'generalheader', get_string('general'));
 
-        $mform->addElement('date_selector', 'reset_start_date', get_string('startdate'), array('optional'=>true));
+        $mform->addElement('date_time_selector', 'reset_start_date', get_string('startdate'), array('optional' => true));
         $mform->addHelpButton('reset_start_date', 'startdate');
-        $mform->addElement('date_selector', 'reset_end_date', get_string('enddate'), array('optional' => true));
+        $mform->addElement('date_time_selector', 'reset_end_date', get_string('enddate'), array('optional' => true));
         $mform->addHelpButton('reset_end_date', 'enddate');
         $mform->addElement('checkbox', 'reset_events', get_string('deleteevents', 'calendar'));
         $mform->addElement('checkbox', 'reset_notes', get_string('deletenotes', 'notes'));
index e1d7944..aeda1d5 100644 (file)
Binary files a/lib/form/amd/build/defaultcustom.min.js and b/lib/form/amd/build/defaultcustom.min.js differ
index 0f280d5..e2e4d11 100644 (file)
@@ -39,6 +39,12 @@ define(['jquery'], function($) {
             form.find('[name="' + elementName + '[day]"]').val(newvalue.day);
             form.find('[name="' + elementName + '[month]"]').val(newvalue.month);
             form.find('[name="' + elementName + '[year]"]').val(newvalue.year);
+        } else if (type === 'date_time_selector') {
+            form.find('[name="' + elementName + '[day]"]').val(newvalue.day);
+            form.find('[name="' + elementName + '[month]"]').val(newvalue.month);
+            form.find('[name="' + elementName + '[year]"]').val(newvalue.year);
+            form.find('[name="' + elementName + '[hour]"]').val(newvalue.hour);
+            form.find('[name="' + elementName + '[minute]"]').val(newvalue.minute);
         }
     };
 
index ab8929a..2169b76 100644 (file)
@@ -84,8 +84,8 @@ class MoodleQuickForm_defaultcustom extends MoodleQuickForm_group {
         if (is_array($options)) {
             foreach ($options as $name => $value) {
                 if (array_key_exists($name, $this->_options)) {
-                    if ($name === 'type' && !in_array($value, ['text', 'date_selector'])) {
-                        throw new coding_exception('Only text and date_selector elements are supported in ' . $this->_type);
+                    if ($name === 'type' && !in_array($value, ['text', 'date_selector', 'date_time_selector'])) {
+                        throw new coding_exception('Only text, date_selector, and date_time_selector elements are supported in ' . $this->_type);
                     }
                     if ($name === 'optional' && $value) {
                         throw new coding_exception('Date selector can not be optional in ' . $this->_type);
@@ -105,6 +105,8 @@ class MoodleQuickForm_defaultcustom extends MoodleQuickForm_group {
         $calendartype = \core_calendar\type_factory::get_calendar_instance();
         $currentdate = $calendartype->timestamp_to_date_array($value, $this->_options['timezone']);
         return array(
+            'minutes' => $currentdate['minutes'],
+            'hours' => $currentdate['hours'],
             'day' => $currentdate['mday'],
             'month' => $currentdate['mon'],
             'year' => $currentdate['year']);
@@ -137,6 +139,9 @@ class MoodleQuickForm_defaultcustom extends MoodleQuickForm_group {
         } else if ($this->_options['type'] === 'date_selector') {
             $element = $this->createFormElement($this->_options['type'], 'value', '', $this->_options,
                 $this->getAttributes());
+        } else if ($this->_options['type'] === 'date_time_selector') {
+            $element = $this->createFormElement($this->_options['type'], 'value', '', $this->_options,
+                $this->getAttributes());
         }
         $this->_elements[] = $element;
     }
@@ -184,10 +189,17 @@ class MoodleQuickForm_defaultcustom extends MoodleQuickForm_group {
                 if ($this->has_customize_switch()) {
                     if ($this->_options['type'] === 'text') {
                         $caller->disabledIf($arg[0] . '[value]', $arg[0] . '[customize]', 'notchecked');
+                    } else if ($this->_options['type'] === 'date_selector') {
+                        $caller->disabledIf($arg[0] . '[value][day]', $arg[0] . '[customize]', 'notchecked');
+                        $caller->disabledIf($arg[0] . '[value][month]', $arg[0] . '[customize]', 'notchecked');
+                        $caller->disabledIf($arg[0] . '[value][year]', $arg[0] . '[customize]', 'notchecked');
                     } else {
+                        // Date / Time selector.
                         $caller->disabledIf($arg[0] . '[value][day]', $arg[0] . '[customize]', 'notchecked');
                         $caller->disabledIf($arg[0] . '[value][month]', $arg[0] . '[customize]', 'notchecked');
                         $caller->disabledIf($arg[0] . '[value][year]', $arg[0] . '[customize]', 'notchecked');
+                        $caller->disabledIf($arg[0] . '[value][hours]', $arg[0] . '[customize]', 'notchecked');
+                        $caller->disabledIf($arg[0] . '[value][minutes]', $arg[0] . '[customize]', 'notchecked');
                     }
                 }
                 return $rv;