From 0f9f31c81c95089d80d591906e5ca36e89e08c54 Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Sat, 18 Feb 2006 20:01:36 +0000 Subject: [PATCH] Using html template for multichoice question --- .../questiontypes/multichoice/display.html | 27 ++++++++++ .../multichoice/questiontype.php | 52 +++++++------------ 2 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 mod/quiz/questiontypes/multichoice/display.html diff --git a/mod/quiz/questiontypes/multichoice/display.html b/mod/quiz/questiontypes/multichoice/display.html new file mode 100644 index 00000000000..383d7eb631b --- /dev/null +++ b/mod/quiz/questiontypes/multichoice/display.html @@ -0,0 +1,27 @@ +
+ questiontext; ?> +
+ +image) { ?> + + + +
+ answerprompt; ?> +
+ + + answers as $answer) { ?> + + + + + + +
+ control; ?> + + feedback; ?> +
diff --git a/mod/quiz/questiontypes/multichoice/questiontype.php b/mod/quiz/questiontypes/multichoice/questiontype.php index f532560a35d..086713d6efa 100644 --- a/mod/quiz/questiontypes/multichoice/questiontype.php +++ b/mod/quiz/questiontypes/multichoice/questiontype.php @@ -254,6 +254,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { } function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { + global $CFG; $answers = &$question->options->answers; $correctanswers = $this->get_correct_responses($question, $state); @@ -263,17 +264,12 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { $formatoptions->para = false; // Print formulation - echo format_text($question->questiontext, + $q->questiontext = format_text($question->questiontext, $question->questiontextformat, NULL, $cmoptions->course); - quiz_print_possible_question_image($question, $cmoptions->course); - - // Print input controls and alternatives - echo ''; - $stranswer = ($question->options->single) ? get_string('singleanswer', 'quiz') : + $q->image = quiz_get_image($question, $cmoptions->course); + $q->answerprompt = ($question->options->single) ? get_string('singleanswer', 'quiz') : get_string('multipleanswers', 'quiz'); - echo "
$stranswer:  "; - echo ''; // Print each answer in a separate row foreach ($state->options->order as $key => $aid) { @@ -281,8 +277,6 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { $qnumchar = chr(ord('a') + $key); $checked = ''; - echo ''; // Print the text by the control highlighting if correct responses // should be shown and the current answer is the correct answer in // the single selection case or has a positive score in the multiple // selection case - if ($options->readonly && $options->correct_responses && - is_array($correctanswers) && in_array($aid, $correctanswers)) { - echo ''; - } else { - echo ''; - } + $a->class = ($options->readonly && $options->correct_responses && + is_array($correctanswers) && in_array($aid, $correctanswers)) ? + 'highlight' : ''; - // Print feedback by selected options if feedback is on - if (($options->feedback || $options->correct_responses) && - $checked) { - echo ''; - } + // Print the answer text + $a->text = format_text("$qnumchar. $answer->answer", FORMAT_MOODLE, $formatoptions); - echo ''; + // Print feedback if feedback is on + $a->feedback = (($options->feedback || $options->correct_responses) && $checked) ? + $feedback = format_text($answer->feedback, true, false) : ''; + + $q->answers[] = clone($a); } - echo '
'; - if ($question->options->single) { $type = 'type="radio"'; $name = "name=\"{$question->name_prefix}\""; @@ -295,41 +289,31 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { $checked = isset($state->responses[$aid]) ? 'checked="checked"' : ''; } - $id = $question->name_prefix . $aid; - $fullid = "id=\"$id\""; + + $a->id = $question->name_prefix . $aid; // Print the control - echo "control = "id\" $name $checked $type value=\"$aid\"" . "alt=\"" . s($answer->answer) . '" />'; - echo ''; - quiz_print_comment($answer->feedback); - echo '
'; - echo '
'; + include("$CFG->dirroot/mod/quiz/questiontypes/multichoice/display.html"); } function grade_responses(&$question, &$state, $cmoptions) {