]> git.mjollnir.org Git - moodle.git/commitdiff
Now latlong data types allow you to choose which labels appear in Google Earth
authordanstowell <danstowell>
Sat, 12 Aug 2006 17:36:22 +0000 (17:36 +0000)
committerdanstowell <danstowell>
Sat, 12 Aug 2006 17:36:22 +0000 (17:36 +0000)
mod/data/field/latlong/field.class.php
mod/data/field/latlong/kml.php
mod/data/field/latlong/mod.html

index 0d18e14cbf56f5c6811f8669af884b17f8058507..2748bb74843d709c029f49158e412a4073b9d049 100755 (executable)
@@ -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);
     }
index d1170958ea3ef11187cc8f9e3fa2603670e1bf7d..5e00a2419fbc184408d29137bbe413aedbb50db6 100644 (file)
@@ -78,12 +78,11 @@ if (isteacher($course->id)) {
 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 = "&lt;a href='$CFG->wwwroot/mod/data/view.php?d=$d&amp;rid=$rid'&gt;Item #$rid&lt;/a&gt; in Moodle data activity";
     $pm->long = $content->content1;
     $pm->lat = $content->content;
@@ -92,14 +91,18 @@ if($rid) { // List one single item
 
     $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 @@ echo data_latlong_kml_bottom();
 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;
+}
index 03adc773915042704bb228557b3bef7a05751636..d0d0c078ea69a608dc7824784b7f0494d347e0e3 100755 (executable)
@@ -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) {
           </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>