]> git.mjollnir.org Git - moodle.git/commitdiff
Better layout of gathering quiz results, which mkes it easier for developers
authormoodler <moodler>
Thu, 24 Jul 2003 02:04:22 +0000 (02:04 +0000)
committermoodler <moodler>
Thu, 24 Jul 2003 02:04:22 +0000 (02:04 +0000)
at the cost of perhaps a little efficiency ... some more testing on this i
should be done.   Thanks to Henrick Kaipe for this.

mod/quiz/attempt.php

index bfac573766b49f4508e944fcf3e50c9112ad8f29..03b80fffcb8e92d84d539f8c655dae5fb5fa1f8e 100644 (file)
         }
 
         foreach ($rawanswers as $key => $value) {       // Parse input for question -> answers
-            if (substr($key, 0, 1) == "q") {
-                $key = substr($key,1);
-                if (isset($questions[$key])) {          // It's a real question number, not a coded one
-                    $questions[$key]->answer[] = trim($value);
-
-                } else if (substr_count($key, "rq")) {  // Random Question information
-                    $check = explode("rq", $key);
-                    $key   = $check[0];                 // The random question id
-                    $real  = $check[1];                 // The real question id
-                    $questions[$key]->random = $real;  
-
-                } else if (substr_count($key, "a")) {   // Checkbox style multiple answers
-                    $check = explode("a", $key);
-                    $key   = $check[0];                 // The main question number
-                    $value = $check[1];                 // The actual answer
-                    $questions[$key]->answer[] = trim($value);  
-
-                } else if (substr_count($key, "r")) {   // Random-style answers
-                    $check = explode("r", $key);
-                    $key   = $check[0];                 // The main question
-                    $rand  = $check[1];                 // The random sub-question
-                    $questions[$key]->answer[] = "$rand-$value";
-
-                } else {
-                    error("Answer received for non-existent question ($key)!");
-                }
-            } else if ($key == "shuffleorder") {
+
+            if (ereg('^q([0-9]+)$', $key, $keyregs)) { // It's a real question number, not a coded one
+                $questions[$keyregs[1]]->answer[] = trim($value);
+
+            } else if (ereg('^q([0-9]+)rq([0-9]+)$', $key, $keyregs)) { // Random Question information
+                $questions[$keyregs[1]]->random = $keyregs[2];
+
+            } else if (ereg('^q([0-9]+)a([0-9]+)$', $key, $keyregs)) { // Checkbox style multiple answers
+                $questions[$keyregs[1]]->answer[] = $keyregs[2];
+
+            } else if (ereg('^q([0-9]+)r([0-9]+)$', $key, $keyregs)) { // Random-style answers
+                $questions[$keyregs[1]]->answer[] = "$keyregs[2]-$value";
+        
+            } else if ('shuffleorder' == $key) {
                 $shuffleorder = explode(",", $value);   // Actual order questions were given in
+            
+            } else {  // Useful for debugging new question types.  Must be last.
+                error("Answer received for non-existent question ($key -> $value)");
             }
         }