From cee5ff1d042badac52d0dcbb3f38fe6827abe8b6 Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 24 Jul 2003 02:04:22 +0000 Subject: [PATCH] Better layout of gathering quiz results, which mkes it easier for developers 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 | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index bfac573766..03b80fffcb 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -92,34 +92,24 @@ } 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)"); } } -- 2.39.5