From: moodler Date: Sun, 20 Oct 2002 05:35:25 +0000 (+0000) Subject: Now shows correct answers, plus some small bug fixes X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8db3eaddb2cf2e5e1cdbea737bd5e6543a3f3b42;p=moodle.git Now shows correct answers, plus some small bug fixes --- diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 9b6c2a5d4f..fc0953329c 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -115,7 +115,9 @@ } if (! $attempt = quiz_save_attempt($quiz, $questions, $result, $numattempts)) { - error("Sorry! Could not save your attempt!"); + notice(get_string("alreadysubmitted", "quiz"), "view.php?id=$cm->id"); + print_footer($course); + exit; } if (! quiz_save_best_grade($quiz, $USER)) { diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index b6f65b058f..aec475b2ce 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -16,9 +16,11 @@ $QUIZ_GRADE_METHOD = array ( GRADEHIGHEST => get_string("gradehighest", "quiz"), define("SHORTANSWER", "1"); define("TRUEFALSE", "2"); define("MULTICHOICE", "3"); +define("RANDOM", "4"); $QUIZ_QUESTION_TYPE = array ( MULTICHOICE => get_string("multichoice", "quiz"), TRUEFALSE => get_string("truefalse", "quiz"), - SHORTANSWER => get_string("shortanswer", "quiz") ); + SHORTANSWER => get_string("shortanswer", "quiz"), + RANDOM => get_string("random", "quiz") ); @@ -213,12 +215,19 @@ function quiz_print_comment($text) { echo "cellheading2\">".text_to_html($text, true, false).""; } +function quiz_print_correctanswer($text) { + global $THEME; + + echo "

$text

"; +} + function quiz_print_question($number, $questionid, $grade, $courseid, - $feedback=NULL, $response=NULL, $actualgrade=NULL) { + $feedback=NULL, $response=NULL, $actualgrade=NULL, $correct=NULL) { /// Prints a quiz question, any format global $THEME; $comment = $THEME->cellheading2; + $green = "#AAFFAA"; if (!$question = get_record("quiz_questions", "id", $questionid)) { notify("Error: Question not found!"); @@ -253,6 +262,10 @@ function quiz_print_question($number, $questionid, $grade, $courseid, if ($feedback) { quiz_print_comment("

$feedback[0]

"); } + if ($correct) { + $correctanswers = implode(",", $correct); + quiz_print_correctanswer($correctanswers); + } break; case TRUEFALSE: @@ -283,10 +296,20 @@ function quiz_print_question($number, $questionid, $grade, $courseid, $falsechecked = "CHECKED"; $feedbackid = $false->id; } - echo "

$stranswer:  "; + if ($correct) { + if ($correct[$true->id]) { + $truecorrect = "CLASS=highlight"; + } + if ($correct[$false->id]) { + $falsecorrect = "CLASS=highlight"; + } + } + echo "
$stranswer:  "; + echo ""; echo "id\" VALUE=\"$true->id\">$true->answer"; - echo "   "; + echo ""; echo "id\" VALUE=\"$false->id\">$false->answer

"; + echo "

"; if ($feedback) { quiz_print_comment("

$feedback[$feedbackid]

"); } @@ -325,7 +348,11 @@ function quiz_print_question($number, $questionid, $grade, $courseid, echo "id"."a$answer->id VALUE=\"$answer->id\">"; } echo ""; - echo "$qnum. $answer->answer"; + if ($feedback and $correct[$answer->id]) { + echo "$qnum. $answer->answer"; + } else { + echo "$qnum. $answer->answer"; + } if ($feedback) { echo " "; if ($response[$answerid]) { @@ -339,6 +366,11 @@ function quiz_print_question($number, $questionid, $grade, $courseid, echo ""; break; + case RANDOM: + echo "

Random questions not supported yet

"; + break; + + default: notify("Error: Unknown question type!"); } @@ -365,14 +397,22 @@ function quiz_print_quiz_questions($quiz, $results=NULL) { echo "id\">"; foreach ($questions as $key => $questionid) { + $feedback = NULL; + $response = NULL; + $actualgrades = NULL; + $correct = NULL; if ($results) { - $feedback = $results->feedback[$questionid]; - } else { - $feedback = NULL; + $feedback = $results->feedback[$questionid]; + $response = $results->response[$questionid]; + $actualgrades = $results->grades[$questionid]; + if ($quiz->correctanswers) { + $correct = $results->correct[$questionid]; + } } + print_simple_box_start("CENTER", "90%"); quiz_print_question($key+1, $questionid, $grades[$questionid]->grade, $quiz->course, - $results->feedback[$questionid], $results->response[$questionid], $results->grades[$questionid]); + $feedback, $response, $actualgrades, $correct); print_simple_box_end(); echo "
"; } @@ -738,6 +778,10 @@ function quiz_get_answers($question) { AND mc.question = g.question"); break; + case RANDOM: + return false; // Not done yet + break; + default: return false; } @@ -843,6 +887,7 @@ function quiz_grade_attempt_results($quiz, $questions) { /// $result->grades[] (array of grades, indexed by question id) /// $result->response[] (array of response arrays, indexed by question id) /// $result->feedback[] (array of feedback arrays, indexed by question id) +/// $result->correct[] (array of feedback arrays, indexed by question id) if (!$questions) { error("No questions!"); @@ -856,6 +901,7 @@ function quiz_grade_attempt_results($quiz, $questions) { } $grade = 0; // default + $correct = array(); $feedback = array(); $response = array(); @@ -868,6 +914,9 @@ function quiz_grade_attempt_results($quiz, $questions) { } $response[0] = $question->answer; foreach($answers as $answer) { // There might be multiple right answers + if ($answer->fraction > $bestshortanswer) { + $correct[$answer->id] = $answer->answer; + } if (!$answer->usecase) { // Don't compare case $answer->answer = strtolower($answer->answer); $question->answer = strtolower($question->answer); @@ -875,7 +924,6 @@ function quiz_grade_attempt_results($quiz, $questions) { if ($question->answer == $answer->answer) { $feedback[0] = $answer->feedback; $grade = (float)$answer->fraction * $answer->grade; - continue; } } break; @@ -889,6 +937,9 @@ function quiz_grade_attempt_results($quiz, $questions) { } foreach($answers as $answer) { // There should be two answers (true and false) $feedback[$answer->id] = $answer->feedback; + if ($answer->fraction > 0) { + $correct[$answer->id] = true; + } if ($question->answer == $answer->id) { $grade = (float)$answer->fraction * $answer->grade; $response[$answer->id] = true; @@ -900,6 +951,10 @@ function quiz_grade_attempt_results($quiz, $questions) { case MULTICHOICE: foreach($answers as $answer) { // There will be multiple answers, perhaps more than one is right $feedback[$answer->id] = $answer->feedback; + if ($answer->fraction > 0) { + $correct[$answer->id] = true; + } + $correct[$answer->id] = $answer->fraction; // 0 or 1 if ($question->answer) { foreach ($question->answer as $questionanswer) { if ($questionanswer == $answer->id) { @@ -916,6 +971,9 @@ function quiz_grade_attempt_results($quiz, $questions) { } } break; + case RANDOM: + // Not done yet + break; } @@ -927,6 +985,7 @@ function quiz_grade_attempt_results($quiz, $questions) { $result->sumgrades += $grade; $result->feedback[$question->id] = $feedback; $result->response[$question->id] = $response; + $result->correct[$question->id] = $correct; } $fraction = (float)($result->sumgrades / $quiz->sumgrades); diff --git a/mod/quiz/question.php b/mod/quiz/question.php index c1e855fc91..b91cb2145f 100644 --- a/mod/quiz/question.php +++ b/mod/quiz/question.php @@ -162,6 +162,9 @@ error("Could not insert quiz multichoice options!"); } break; + case RANDOM: + echo "

Not supported yet

"; + break; default: error("Non-existent question type!"); break; @@ -237,6 +240,10 @@ print_heading(get_string("editingmultichoice", "quiz")); require("multichoice.html"); break; + case RANDOM: + print_heading("Not supported yet"); + print_continue("edit.php"); + break; default: error("Invalid question type");