MDL-55804 forms: Return exported data through _prepareValue

This commit is contained in:
David Monllao 2016-08-31 13:31:59 +08:00
parent 26162efe4a
commit 80180e0f92
5 changed files with 9 additions and 13 deletions

View File

@ -232,7 +232,7 @@ class core_calendar_type_testcase extends advanced_testcase {
}
$submitvalues = array('dateselector' . $counter => $date);
$this->assertSame($el->exportValue($submitvalues), array('dateselector' . $counter => $date['timestamp']));
$this->assertSame(array('dateselector' . $counter => $date['timestamp']), $el->exportValue($submitvalues, true));
}
/**

View File

@ -263,7 +263,6 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group {
* @return array
*/
function exportValue(&$submitValues, $assoc = false) {
$value = null;
$valuearray = array();
foreach ($this->_elements as $element){
$thisexport = $element->exportValue($submitValues[$this->getName()], true);
@ -275,21 +274,20 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group {
if($this->_options['optional']) {
// If checkbox is on, the value is zero, so go no further
if(empty($valuearray['enabled'])) {
$value[$this->getName()] = 0;
return $value;
return $this->_prepareValue(0, $assoc);
}
}
// Get the calendar type used - see MDL-18375.
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$gregoriandate = $calendartype->convert_to_gregorian($valuearray['year'], $valuearray['month'], $valuearray['day']);
$value[$this->getName()] = make_timestamp($gregoriandate['year'],
$value = make_timestamp($gregoriandate['year'],
$gregoriandate['month'],
$gregoriandate['day'],
0, 0, 0,
$this->_options['timezone'],
true);
return $value;
return $this->_prepareValue($value, $assoc);
} else {
return null;
}

View File

@ -286,7 +286,6 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group {
* @return array
*/
function exportValue(&$submitValues, $assoc = false) {
$value = null;
$valuearray = array();
foreach ($this->_elements as $element){
$thisexport = $element->exportValue($submitValues[$this->getName()], true);
@ -298,8 +297,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group {
if($this->_options['optional']) {
// If checkbox is on, the value is zero, so go no further
if(empty($valuearray['enabled'])) {
$value[$this->getName()] = 0;
return $value;
return $this->_prepareValue(0, $assoc);
}
}
// Get the calendar type used - see MDL-18375.
@ -309,7 +307,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group {
$valuearray['day'],
$valuearray['hour'],
$valuearray['minute']);
$value[$this->getName()] = make_timestamp($gregoriandate['year'],
$value = make_timestamp($gregoriandate['year'],
$gregoriandate['month'],
$gregoriandate['day'],
$gregoriandate['hour'],
@ -318,7 +316,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group {
$this->_options['timezone'],
true);
return $value;
return $this->_prepareValue($value, $assoc);
} else {
return null;
}

View File

@ -133,7 +133,7 @@ class core_form_dateselector_testcase extends advanced_testcase {
$this->assertTrue($el instanceof MoodleQuickForm_date_selector);
$submitvalues = array('dateselector' => $vals);
$this->assertSame(array('dateselector' => $vals['timestamp']), $el->exportValue($submitvalues),
$this->assertSame(array('dateselector' => $vals['timestamp']), $el->exportValue($submitvalues, true),
"Please check if timezones are updated (Site adminstration -> location -> update timezone)");
}
}

View File

@ -145,7 +145,7 @@ class core_form_datetimeselector_testcase extends advanced_testcase {
$this->assertTrue($el instanceof MoodleQuickForm_date_time_selector);
$submitvalues = array('dateselector' => $vals);
$this->assertSame(array('dateselector' => $vals['timestamp']), $el->exportValue($submitvalues),
$this->assertSame(array('dateselector' => $vals['timestamp']), $el->exportValue($submitvalues, true),
"Please check if timezones are updated (Site adminstration -> location -> update timezone)");
}
}