Skip to content

Commit

Permalink
Merge branch 'MDL-43648_m35v2' of https://github.com/sbourget/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 9, 2018
2 parents f9b3597 + 57422d7 commit 61f56fd
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions admin/tool/uploadcourse/classes/step2_form.php
Expand Up @@ -93,11 +93,11 @@ public function definition () {
$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);
Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/restore_course_task.class.php
Expand Up @@ -200,7 +200,7 @@ protected function define_settings() {
$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);
Expand Down
4 changes: 0 additions & 4 deletions backup/util/plan/restore_step.class.php
Expand Up @@ -84,10 +84,6 @@ public function apply_date_offset($value) {
// 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;
Expand Down
9 changes: 5 additions & 4 deletions course/edit_form.php
Expand Up @@ -120,12 +120,13 @@ function definition() {
$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"');
Expand Down
4 changes: 2 additions & 2 deletions course/reset_form.php
Expand Up @@ -41,9 +41,9 @@ function definition (){

$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'));
Expand Down
2 changes: 1 addition & 1 deletion lib/form/amd/build/defaultcustom.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/form/amd/src/defaultcustom.js
Expand Up @@ -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);
}
};

Expand Down
16 changes: 14 additions & 2 deletions lib/form/defaultcustom.php
Expand Up @@ -84,8 +84,8 @@ public function __construct($elementname = null, $elementlabel = null, $options
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);
Expand All @@ -105,6 +105,8 @@ protected function timestamp_to_date_array($value) {
$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']);
Expand Down Expand Up @@ -137,6 +139,9 @@ public function _createElements() {
} 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;
}
Expand Down Expand Up @@ -184,10 +189,17 @@ public function onQuickFormEvent($event, $arg, &$caller) {
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;
Expand Down

0 comments on commit 61f56fd

Please sign in to comment.