]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10799 - Question types do not accurately determine whether their state has change...
authortjhunt <tjhunt>
Fri, 10 Aug 2007 15:21:29 +0000 (15:21 +0000)
committertjhunt <tjhunt>
Fri, 10 Aug 2007 15:21:29 +0000 (15:21 +0000)
question/type/multichoice/questiontype.php
question/type/questiontype.php

index 965921006df9ab7fd4bcfe87a32aeb0fd920abe0..270592f8ced45758c75f5e1edef988f72a3749fd 100644 (file)
@@ -189,8 +189,7 @@ class question_multichoice_qtype extends default_questiontype {
         if (false === $pos) { // No order of answers is given, so use the default
             $state->options->order = array_keys($question->options->answers);
         } else { // Restore the order of the answers
-            $state->options->order = explode(',', substr($state->responses[''], 0,
-             $pos));
+            $state->options->order = explode(',', substr($state->responses[''], 0, $pos));
             $state->responses[''] = substr($state->responses[''], $pos + 1);
         }
         // Restore the responses
@@ -200,11 +199,7 @@ class question_multichoice_qtype extends default_questiontype {
         // the $state->responses array is indexed by the answer ids and the
         // values are also the answer ids (i.e. key = value).
         if (empty($state->responses[''])) { // No previous responses
-            if ($question->options->single) {
-                $state->responses = array('' => '');
-            } else {
-                $state->responses = array();
-            }
+            $state->responses = array('' => '');
         } else {
             if ($question->options->single) {
                 $state->responses = array('' => $state->responses['']);
index a7ad604cd3e0d0748479c104d8c457dca4c9a702..354fffddd1da9b35f511e4bf4bfffef52bf65126 100644 (file)
@@ -1157,7 +1157,16 @@ class default_questiontype {
         // Question types may wish to override this (eg. to ignore trailing
         // white space or to make "7.0" and "7" compare equal).
 
-        return $state->responses === $teststate->responses;
+        // In php neither == nor === compare arrays the way you want. The following 
+        // ensures that the arrays have the same keys, with the same values.
+        $result = false;
+        $diff1 = array_diff_assoc($state->responses, $teststate->responses);
+        if (empty($diff1)) {
+            $diff2 = array_diff_assoc($teststate->responses, $state->responses);
+            $result =  empty($diff2);
+        }
+
+        return $result;
     }
 
     /**