Permalink
Browse files

Now latlong data types allow you to choose which labels appear in Goo…

…gle Earth
  • Loading branch information...
danstowell
danstowell committed Aug 12, 2006
1 parent b8a607d commit 3af692dba0d30d6c1ab31eb9fcc135a60d7b0831
Showing with 52 additions and 6 deletions.
  1. +6 −0 mod/data/field/latlong/field.class.php
  2. +25 −5 mod/data/field/latlong/kml.php
  3. +21 −1 mod/data/field/latlong/mod.html
@@ -41,6 +41,12 @@ class data_field_latlong extends data_field_base {
// Parameter data used:
// "param1" is a comma-separated list of the linkout service names that are enabled for this instance
// "param2" indicates the label that will be used in generating Google Earth KML files: -1 for item #, -2 for lat/long, positive number for the (text) field to use.
function data_field_latlong($field=0, $data=0) {
parent::data_field_base($field, $data);
}
@@ -78,12 +78,11 @@
header('Content-type: application/vnd.google-earth.kml+xml kml');
header('Content-Disposition: attachment; filename="moodleearth-'.$d.'-'.$rid.'-'.$fieldid.'.kml"');
//print_r($record);
echo data_latlong_kml_top();
if($rid) { // List one single item
$pm->name = "Item #$rid";
$pm->name = data_latlong_kml_get_item_name($content, $field);
$pm->description = "<a href='$CFG->wwwroot/mod/data/view.php?d=$d&rid=$rid'>Item #$rid</a> in Moodle data activity";
$pm->long = $content->content1;
$pm->lat = $content->content;
@@ -92,14 +91,18 @@
$contents = get_records('data_content', 'fieldid', $fieldid);
echo '<Document>';
foreach($contents as $content) {
$pm->name = "Item #$content->recordid";
$pm->name = data_latlong_kml_get_item_name($content, $field);
$pm->description = "&lt;a href='$CFG->wwwroot/mod/data/view.php?d=$d&amp;rid=$content->recordid'&gt;Item #$content->recordid&lt;/a&gt; in Moodle data activity";
$pm->long = $content->content1;
$pm->lat = $content->content;
echo data_latlong_kml_placemark($pm);
}
echo '</Document>';
}
echo data_latlong_kml_bottom();
@@ -110,7 +113,7 @@
function data_latlong_kml_top() {
return '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
';
}
@@ -136,6 +139,23 @@ function data_latlong_kml_placemark($pm) {
}
function data_latlong_kml_bottom() {
return '</Document></kml>';
return '</kml>';
}
function data_latlong_kml_get_item_name($content, $field) {
// $field->param2 contains the user-specified labelling method
$name = '';
if($field->param2 > 0) {
$name = htmlspecialchars(get_field('data_content', 'content', 'fieldid', $field->param2, 'recordid', $content->recordid));
}elseif($field->param2 == -2) {
$name = $content->content . ', ' . $content->content1;
}
if($name=='') { // Done this way so that "item #" is the default that catches any problems
$name = get_string('entry', 'data') . " #$content->recordid";
}
return $name;
}
@@ -10,7 +10,7 @@
<tr>
<td class="c0"><?php echo get_string('latlonglinkservicesdisplayed', 'data'); ?>:</td>
<td class="c1">
<select class="linkservicesdisplayed" type="text" name="param1[]" id="param1" multiple="multiple" size="<?php echo sizeof($this->linkoutservices) ?>">
<select class="linkservicesdisplayed" name="param1[]" id="param1" multiple="multiple" size="<?php echo sizeof($this->linkoutservices) ?>">
<?php
$serviceschosen = explode(',', htmlspecialchars($this->field->param1));
foreach($this->linkoutservices as $servicename=>$serviceurl) {
@@ -21,4 +21,24 @@
</select>
</td>
</tr>
<tr>
<td class="c0"><?php echo get_string('latlongkmllabelling', 'data'); ?>:</td>
<td class="c1">
<select class="kmllabelling" name="param2" id="param2">
<option value="-1"<?php if($this->field->param2==-1) echo ' selected="selected"' ?>><?php echo get_string('entry', 'data') ?> #</option>
<option value="-2"<?php if($this->field->param2==-2) echo ' selected="selected"' ?>><?php echo get_string('latitude', 'data').'/'.get_string('longitude', 'data') ?></option>
<?php
// Fetch all "suitable" other fields that exist for this database
$textfields = get_records_select('data_fields', 'dataid='.$this->data->id.' AND type="text"');
echo '<optgroup label="'.get_string('latlongotherfields', 'data').':">';
if(sizeof($textfields)>0) {
foreach($textfields as $textfield) {
echo "<option value='$textfield->id'".($this->field->param2==$textfield->id ? ' selected="selected"' : '').">$textfield->name</option>";
}
}
echo '</optgroup>';
?>
</select>
</td>
</tr>
</table>

0 comments on commit 3af692d

Please sign in to comment.