From: moodler Date: Mon, 22 Nov 2004 16:25:29 +0000 (+0000) Subject: I've not tested this at all :-( but it was sent to me by the original X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b5c6d80dfe874ec3279ba93927633a12d897ed3c;p=moodle.git I've not tested this at all :-( but it was sent to me by the original author of this feature as a bug fix. PLEASE TEST! (See bug 2179 for example) --- diff --git a/mod/quiz/preview.php b/mod/quiz/preview.php index 5f94b4d3d3..32354025f4 100644 --- a/mod/quiz/preview.php +++ b/mod/quiz/preview.php @@ -61,8 +61,6 @@ print_header(); print_heading(get_string("previewquestion","quiz")); - echo "

"; - if (empty($question->id)) { $question->id = ""; } @@ -88,47 +86,38 @@ $answers = array(); $feedbacks = array(); $qids = array(); + $fraction = 0; foreach ($rawanswers as $key => $value) { // Parse input for question->response $postedId = quiz_extract_posted_id($key); - if ($id == $postedId) { - $question->response[$key] = trim($value); - $questionType = $QUIZ_QTYPES[$question->qtype]->name(); - $rezult = get_exp_answers($id); //answers from the database - - if($rezult) { - foreach ($rezult as $qid => $answer) { - if($qid == $value || $answer->answer == $value) { - $feedbacks[$qid] = " - ".format_text($answer->feedback, true, false).""; - if($answer->fraction > 0) - $answers[$qid] = "" . $answer->answer . ""; - else - $answers[$qid] = $answer->answer; - } else { - if(!isset($answers[$qid])) { - if($answer->fraction > 0) - $answers[$qid] = "" . $answer->answer . ""; - else - $answers[$qid] = $answer->answer; - $feedbacks[$qid] = ''; - } - } - $qids[] = $qid; - } - }//end if rezult - }//end if pId==id + if ($id == $postedId) $question->response[$key] = trim($value); }//end for each rowanswers print_simple_box_start("center", "90%"); + + //simulate quiz only for quiestion previews + class FakeQuiz { + var $correctanswers; + var $feedback; + var $grade; + function FakeQuiz() + { + $this->correctanswers = 1; + $this->feedback = 1; + $this->grade = 1; + } + }; + + $question->maxgrade = 1; //this shouldn't be like that + $resultdetails = $QUIZ_QTYPES[$question->qtype]->grade_response($question, quiz_qtype_nameprefix($question)); + $quiz = new FakeQuiz(); + $QUIZ_QTYPES[$question->qtype]->print_question - (1, 0, $question, true, $resultdetails); + (1, $quiz, $question, true, $resultdetails); - $qids = array_unique($qids); //erease duplicates - for($i = 0; $i < count($qids); $i++) { - global $THEME; - echo "

" . $answers[$qids[$i]] . format_text($feedbacks[$qids[$i]], true, false)."

"; - } print_simple_box_end(); + echo "

\n"; + echo "

\n"; } else {//show question list echo "
\n"; @@ -141,7 +130,8 @@ echo "
"; echo "
"; - echo "\n"; + echo "\n"; + echo ""; echo "
"; echo "
"; }