From aca1dc1b63ae15cf4e063ddfde88dda1398ce374 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 1ececad10dd..59c01c6c0de 100644 --- a/lib/form/dateselector.php +++ b/lib/form/dateselector.php @@ -259,7 +259,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); @@ -271,21 +270,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 bdf7e96b28e..15126f219e7 100644 --- a/lib/form/datetimeselector.php +++ b/lib/form/datetimeselector.php @@ -282,7 +282,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); @@ -294,8 +293,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. @@ -305,7 +303,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'], @@ -314,7 +312,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)"); } }