From 8b27687b5f88e344120568a3b0cb9bdca85d78fb Mon Sep 17 00:00:00 2001 From: David Monllao Date: Wed, 31 Aug 2016 13:31:59 +0800 Subject: [PATCH] MDL-55804 forms: Return exported data through _prepareValue --- calendar/tests/calendartype_test.php | 2 +- lib/form/dateselector.php | 8 +++----- lib/form/datetimeselector.php | 8 +++----- lib/form/tests/dateselector_test.php | 2 +- lib/form/tests/datetimeselector_test.php | 2 +- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/calendar/tests/calendartype_test.php b/calendar/tests/calendartype_test.php index c124477dc83..fdf6ee9184d 100644 --- a/calendar/tests/calendartype_test.php +++ b/calendar/tests/calendartype_test.php @@ -224,7 +224,7 @@ class core_calendar_type_testcase extends advanced_testcase { $el->_createElements(); $submitvalues = array('dateselector' => $date); - $this->assertSame($el->exportValue($submitvalues), array('dateselector' => $date['timestamp'])); + $this->assertSame(array('dateselector' => $date['timestamp']), $el->exportValue($submitvalues, true)); } /** diff --git a/lib/form/dateselector.php b/lib/form/dateselector.php index 29957e3d904..c7dfad279b5 100644 --- a/lib/form/dateselector.php +++ b/lib/form/dateselector.php @@ -262,7 +262,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); @@ -274,21 +273,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; } diff --git a/lib/form/datetimeselector.php b/lib/form/datetimeselector.php index 8055f026e6f..aa4951b3d44 100644 --- a/lib/form/datetimeselector.php +++ b/lib/form/datetimeselector.php @@ -285,7 +285,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); @@ -297,8 +296,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. @@ -308,7 +306,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'], @@ -317,7 +315,7 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group { $this->_options['timezone'], true); - return $value; + return $this->_prepareValue($value, $assoc); } else { return null; } diff --git a/lib/form/tests/dateselector_test.php b/lib/form/tests/dateselector_test.php index f6e4e24198d..c2b003109de 100644 --- a/lib/form/tests/dateselector_test.php +++ b/lib/form/tests/dateselector_test.php @@ -133,7 +133,7 @@ class core_form_dateselector_testcase extends advanced_testcase { $el->_createElements(); $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)"); } } diff --git a/lib/form/tests/datetimeselector_test.php b/lib/form/tests/datetimeselector_test.php index ba188ee35b9..db3bdad60a1 100644 --- a/lib/form/tests/datetimeselector_test.php +++ b/lib/form/tests/datetimeselector_test.php @@ -145,7 +145,7 @@ class core_form_datetimeselector_testcase extends advanced_testcase { $el->_createElements(); $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)"); } }