Permalink
Browse files

MDL-37356 - mod_data: Database activity now uses format_float and unf…

…ormat_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.
  • Loading branch information...
1 parent 1dd6835 commit cffc08a63d93e0add18d6e96037c7a951df0ddb2 @abgreeve abgreeve committed Feb 8, 2013
Showing with 19 additions and 7 deletions.
  1. +13 −6 mod/data/field/latlong/field.class.php
  2. +6 −1 mod/data/import.php
@@ -78,7 +78,9 @@ function display_search_field($value = '') {
$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 @@ function display_browse_field($recordid, $template) {
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 @@ function display_browse_field($recordid, $template) {
if(sizeof($servicesshown)==1 && $servicesshown[0]) {
$str = " <a href='"
. str_replace(array_keys($urlreplacements), array_values($urlreplacements), $this->linkoutservices[$servicesshown[0]])
- ."' title='$servicesshown[0]'>$compasslat, $compasslong</a>";
+ ."' title='$servicesshown[0]'>$compasslat $compasslong</a>";
} elseif (sizeof($servicesshown)>1) {
$str = '<form id="latlongfieldbrowse">';
$str .= "$compasslat, $compasslong\n";
@@ -180,6 +183,9 @@ function update_content($recordid, $value, $name='') {
$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 @@ function get_sort_sql($fieldname) {
}
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);
}
View
@@ -156,7 +156,12 @@
// 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).

0 comments on commit cffc08a

Please sign in to comment.