]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18542:
authorthepurpleblob <thepurpleblob>
Thu, 19 Mar 2009 20:45:40 +0000 (20:45 +0000)
committerthepurpleblob <thepurpleblob>
Thu, 19 Mar 2009 20:45:40 +0000 (20:45 +0000)
Correctly deals with field types that have multiple parts (e.g. data and lat/long)
Thanks to Eloy for spotting this.

Merged from STABLE_19

mod/data/edit.php
mod/data/field/date/field.class.php
mod/data/field/latlong/field.class.php
mod/data/lib.php

index db985c091a3b76a08a467af6d67212bfe644a9f6..d7646a167682b28f21a001c6afaca57b0591c338 100755 (executable)
     }
     include('tabs.php');
 
-
 /// Process incoming data for adding/updating records
 
     if ($datarecord = data_submitted() and confirm_sesskey()) {
             /// Update all content
             $field = NULL;
             foreach ($fieldids as $fieldid) {
-                    $name = "field_$fieldid";
-                    $value = optional_param( $name,'' );
-                    if (empty($field->field) || ($fieldid != $field->field->id)) {  // Try to reuse classes
-                        $field = data_get_field_from_id($fieldid, $data);
-                    }
-                    if ($field) {
-                        $field->update_content($rid, $value, $name);
-                    }
+                $bits = explode('_',$fieldid);
+                $justid = $bits[0];
+                $name = "field_$fieldid";
+                $value = optional_param( $name,'' );
+                if (empty($field->field) || ($justid != $field->field->id)) {  // Try to reuse classes
+                    $field = data_get_field_from_id($fieldid, $data);
+                }
+                if ($field) {
+                    $field->update_content($rid, $value, $name);
+                }
             }
 
             add_to_log($course->id, 'data', 'update', "view.php?d=$data->id&amp;rid=$rid", $data->id, $cm->id);
             $emptyform = true;      // assume the worst
 
             foreach ($fieldids as $fieldid) {
+                $bits = explode('_',$fieldid);
+                $justid = $bits[0];
                 $name = "field_$fieldid";
                 $value = optional_param( $name,'' );
-                if (empty($field->field) || ($fieldid != $field->field->id)) {  // Try to reuse classes
+                if (empty($field->field) || ($justid != $field->field->id)) {  // Try to reuse classes
                     $field = data_get_field_from_id($fieldid, $data);
                 }
                 if ($field->notemptyfield($value, $name)) {
                     break;             // if anything has content, this form is not empty, so stop now!
                 }
             }
-
             if ($emptyform){    //nothing gets written to database
                 notify(get_string('emptyaddform','data'));
             }
 
                 //for each field in the add form, add it to the data_content.
                 foreach ($fieldids as $fieldid) {
+                    $bits = explode('_',$fieldid);
+                    $justid = $bits[0];
                     $name = "field_$fieldid";
                     $value = optional_param( $name,'' );
-                    if (empty($field->field) || ($fieldid != $field->field->id)) {  // Try to reuse classes
+                    if (empty($field->field) || ($justid != $field->field->id)) {  // Try to reuse classes
                         $field = data_get_field_from_id($fieldid, $data);
                     }
                     if ($field) {
                         $field->update_content($recordid, $value, $name);
                     }
                 }  
-
                 add_to_log($course->id, 'data', 'add', "view.php?d=$data->id&amp;rid=$recordid", $data->id, $cm->id);
 
                 notify(get_string('entrysaved','data'));
             $replacements[] = $field->display_add_field($rid);
             $patterns[]="[[".$field->field->name."#id]]";
             $replacements[] = 'field_'.$field->field->id;
-            $data->fieldids[] = $field->field->id;
+            $field->list_add_field( $data->fieldids );
         }
         $newtext = str_ireplace($patterns, $replacements, $data->{$mode});
 
index 6d7297cd1193c45c50791cf90a42c84766c684e6..c90b2d4a75b5986de24dbad9da521569074d7a73 100755 (executable)
@@ -50,7 +50,14 @@ class data_field_date extends data_field_base {
 
         return $str;
     }
-    
+
+    function list_add_field(&$fields) {
+        $fields[] = $this->field->id.'_day';
+        $fields[] = $this->field->id.'_month';
+        $fields[] = $this->field->id.'_year';
+        return true;
+    }
+
     //Enable the following three functions once core API issues have been addressed.
     function display_search_field($value=0) {
         return false;
@@ -82,11 +89,9 @@ class data_field_date extends data_field_base {
 
         $names = explode('_',$name);
         $name = $names[2];          // day month or year
-
         $this->$name = $value;
 
         if ($this->day and $this->month and $this->year) {  // All of them have been collected now
-
             $content = new object;
             $content->fieldid = $this->field->id;
             $content->recordid = $recordid;
index 87ed62a7d40d1f27c3689ebaddc830e1a43f6068..81c047c5f8d68557e93227cd2e001bf07b536e30 100755 (executable)
@@ -65,6 +65,12 @@ class data_field_latlong extends data_field_base {
         return $str;
     }
 
+    function list_add_field( &$fields ) {
+        $fields[] = $this->field->id.'_0';
+        $fields[] = $this->field->id.'_1';
+        return true;
+    }
+
     function display_search_field($value = '') {
         global $CFG, $DB;
         $lats = $DB->get_records_sql_menu('SELECT id, content FROM {data_content} WHERE fieldid=? GROUP BY content ORDER BY content', array($this->field->id));
index 89b7605fd978f605f37efb67c2d0cf6f2ff69cab..c875b8c9f5dc6a7ed3b05f7228be57d8e1d38c04 100755 (executable)
@@ -205,6 +205,14 @@ class data_field_base {     // Base class for Database Field Types (see field/*/
         return $str;
     }
 
+
+// add the field ids to an existing array to track added form fields
+// override if anything with multiple fields (e.g. date)
+    function list_add_field( &$fields ) {
+        $fields[] = $this->field->id;
+        return true;
+    }
+
 // Print the relevant form element to define the attributes for this field
 // viewable by teachers only.
     function display_edit_field() {
@@ -407,7 +415,7 @@ function data_generate_default_template(&$data, $template, $recordid=0, $form=fa
             if ($form) {   // Print forms instead of data
                 $fieldobj = data_get_field($field, $data);
                 $str .= $fieldobj->display_add_field($recordid);
-                $data->fieldids[] = $fieldobj->field->id;
+                $fieldobj->list_add_field( $data->fieldids );
             } else {           // Just print the tag
                 $str .= '[['.$field->name.']]';
             }