From cffc08a63d93e0add18d6e96037c7a951df0ddb2 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Fri, 8 Feb 2013 09:06:50 +0800 Subject: [PATCH] MDL-37356 - mod_data: Database activity now uses format_float and unformat_float. The longitude and latitude values were not using format_float and unformat_float. Changes have been made to the manual entry of records, csv import of records, and the display of these records. --- mod/data/field/latlong/field.class.php | 19 +++++++++++++------ mod/data/import.php | 7 ++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/mod/data/field/latlong/field.class.php b/mod/data/field/latlong/field.class.php index e94169996bc..e6108eec2bb 100644 --- a/mod/data/field/latlong/field.class.php +++ b/mod/data/field/latlong/field.class.php @@ -78,7 +78,9 @@ class data_field_latlong extends data_field_base { $options = array(); foreach ($latlongsrs as $latlong) { - $options[$latlong->la . ',' . $latlong->lo] = $latlong->la . ',' . $latlong->lo; + $latitude = format_float($latlong->la, 4); + $longitude = format_float($latlong->lo, 4); + $options[$latlong->la . ',' . $latlong->lo] = $latitude . ' ' . $longitude; } $latlongsrs->close(); @@ -120,15 +122,16 @@ class data_field_latlong extends data_field_base { if (strlen($long) < 1) { return false; } + // We use format_float to display in the regional format. if($lat < 0) { - $compasslat = sprintf('%01.4f', -$lat) . '°S'; + $compasslat = format_float(-$lat, 4) . '°S'; } else { - $compasslat = sprintf('%01.4f', $lat) . '°N'; + $compasslat = format_float($lat, 4) . '°N'; } if($long < 0) { - $compasslong = sprintf('%01.4f', -$long) . '°W'; + $compasslong = format_float(-$long, 4) . '°W'; } else { - $compasslong = sprintf('%01.4f', $long) . '°E'; + $compasslong = format_float($long, 4) . '°E'; } // Now let's create the jump-to-services link @@ -149,7 +152,7 @@ class data_field_latlong extends data_field_base { if(sizeof($servicesshown)==1 && $servicesshown[0]) { $str = " $compasslat, $compasslong"; + ."' title='$servicesshown[0]'>$compasslat $compasslong"; } elseif (sizeof($servicesshown)>1) { $str = '
'; $str .= "$compasslat, $compasslong\n"; @@ -180,6 +183,9 @@ class data_field_latlong extends data_field_base { $content = new stdClass(); $content->fieldid = $this->field->id; $content->recordid = $recordid; + // When updating these values (which might be region formatted) we should format + // the float to allow for a consistent float format in the database. + $value = unformat_float($value); $value = trim($value); if (strlen($value) > 0) { $value = floatval($value); @@ -213,6 +219,7 @@ class data_field_latlong extends data_field_base { } function export_text_value($record) { + // The content here is from the database and does not require location formating. return sprintf('%01.4f', $record->content) . ' ' . sprintf('%01.4f', $record->content1); } diff --git a/mod/data/import.php b/mod/data/import.php index 5a4526b10c3..9b7425b7973 100644 --- a/mod/data/import.php +++ b/mod/data/import.php @@ -156,7 +156,12 @@ if (!$formdata = $form->get_data()) { // for now, only for "latlong" and "url" fields, but that should better be looked up from // $CFG->dirroot . '/mod/data/field/' . $field->type . '/field.class.php' // once there is stored how many contents the field can have. - if (preg_match("/^(latlong|url)$/", $field->type)) { + if ($field->type == 'latlong') { + $values = explode(" ", $value, 2); + // The lat, long values might be in a different float format. + $content->content = unformat_float($values[0]); + $content->content1 = unformat_float($values[1]); + } else if ($field->type == 'url') { $values = explode(" ", $value, 2); $content->content = $values[0]; // The url field doesn't always have two values (unforced autolinking).