]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17228 Synchronizing dataitems between calculated questions in a quiz
authorpichetp <pichetp>
Tue, 18 Nov 2008 18:28:20 +0000 (18:28 +0000)
committerpichetp <pichetp>
Tue, 18 Nov 2008 18:28:20 +0000 (18:28 +0000)
question/type/calculated/questiontype.php

index 60b627e9029535e2d6ee6e1faa16f3ead96225c7..5c330b9ff6cb5a7531bdc4491628f95f0f776a7a 100644 (file)
@@ -321,7 +321,20 @@ class question_calculated_qtype extends default_questiontype {
         }
 
         // Choose a random dataset
-        $state->options->datasetitem = rand(1, $maxnumber);
+        if (!isset($cmoptions->intro) || strstr($cmoptions->intro, 'synchronize_calculated') === false ) {
+            $state->options->datasetitem = rand(1, $maxnumber);
+        }else{
+            if( !isset($cmoptions->synchronize_calculated)) {
+               $state->options->datasetitem = rand(1, $maxnumber);
+               $cmoptions->synchronize_calculated = $state->options->datasetitem ;
+            }else {
+                if ($cmoptions->synchronize_calculated <= $maxnumber){
+                    $state->options->datasetitem = $cmoptions->synchronize_calculated ;
+                }else {
+                    $state->options->datasetitem = rand(1, $maxnumber);
+                }
+            }
+        };  
         $state->options->dataset =
          $this->pick_question_dataset($question,$state->options->datasetitem);
         $state->responses = array('' => '');