mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
Using html template for multichoice question
This commit is contained in:
parent
bffa0685da
commit
0f9f31c81c
2 changed files with 45 additions and 34 deletions
27
mod/quiz/questiontypes/multichoice/display.html
Normal file
27
mod/quiz/questiontypes/multichoice/display.html
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<div>
|
||||||
|
<?php echo $q->questiontext; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($q->image) { ?>
|
||||||
|
<img border="0" src="<?php echo $q->imageurl; ?>" alt="" />
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<?php echo $q->answerprompt; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<?php foreach ($q->answers as $answer) { ?>
|
||||||
|
<tr>
|
||||||
|
<td valign="top">
|
||||||
|
<?php echo $answer->control; ?>
|
||||||
|
</td>
|
||||||
|
<td valign="top" class="<?php echo $answer->class ?>"><label for="<?php echo $answer->id ?>">
|
||||||
|
<?php echo $answer->text; ?>
|
||||||
|
</td>
|
||||||
|
<td valign="top" class="feedbacktext">
|
||||||
|
<?php echo $answer->feedback; ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</table>
|
|
@ -254,6 +254,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
|
function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
$answers = &$question->options->answers;
|
$answers = &$question->options->answers;
|
||||||
$correctanswers = $this->get_correct_responses($question, $state);
|
$correctanswers = $this->get_correct_responses($question, $state);
|
||||||
|
@ -263,17 +264,12 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
|
||||||
$formatoptions->para = false;
|
$formatoptions->para = false;
|
||||||
|
|
||||||
// Print formulation
|
// Print formulation
|
||||||
echo format_text($question->questiontext,
|
$q->questiontext = format_text($question->questiontext,
|
||||||
$question->questiontextformat,
|
$question->questiontextformat,
|
||||||
NULL, $cmoptions->course);
|
NULL, $cmoptions->course);
|
||||||
quiz_print_possible_question_image($question, $cmoptions->course);
|
$q->image = quiz_get_image($question, $cmoptions->course);
|
||||||
|
$q->answerprompt = ($question->options->single) ? get_string('singleanswer', 'quiz') :
|
||||||
// Print input controls and alternatives
|
|
||||||
echo '<table align="right">';
|
|
||||||
$stranswer = ($question->options->single) ? get_string('singleanswer', 'quiz') :
|
|
||||||
get_string('multipleanswers', 'quiz');
|
get_string('multipleanswers', 'quiz');
|
||||||
echo "<tr><td valign=\"top\">$stranswer: </td><td>";
|
|
||||||
echo '<table>';
|
|
||||||
|
|
||||||
// Print each answer in a separate row
|
// Print each answer in a separate row
|
||||||
foreach ($state->options->order as $key => $aid) {
|
foreach ($state->options->order as $key => $aid) {
|
||||||
|
@ -281,8 +277,6 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
|
||||||
$qnumchar = chr(ord('a') + $key);
|
$qnumchar = chr(ord('a') + $key);
|
||||||
$checked = '';
|
$checked = '';
|
||||||
|
|
||||||
echo '<tr><td valign="top">';
|
|
||||||
|
|
||||||
if ($question->options->single) {
|
if ($question->options->single) {
|
||||||
$type = 'type="radio"';
|
$type = 'type="radio"';
|
||||||
$name = "name=\"{$question->name_prefix}\"";
|
$name = "name=\"{$question->name_prefix}\"";
|
||||||
|
@ -295,41 +289,31 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
|
||||||
$checked = isset($state->responses[$aid])
|
$checked = isset($state->responses[$aid])
|
||||||
? 'checked="checked"' : '';
|
? 'checked="checked"' : '';
|
||||||
}
|
}
|
||||||
$id = $question->name_prefix . $aid;
|
|
||||||
$fullid = "id=\"$id\"";
|
$a->id = $question->name_prefix . $aid;
|
||||||
|
|
||||||
// Print the control
|
// Print the control
|
||||||
echo "<input $readonly $fullid $name $checked $type value=\"$aid\"" .
|
$a->control = "<input $readonly id=\"$a->id\" $name $checked $type value=\"$aid\"" .
|
||||||
"alt=\"" . s($answer->answer) . '" />';
|
"alt=\"" . s($answer->answer) . '" />';
|
||||||
echo '</td>';
|
|
||||||
|
|
||||||
// Print the text by the control highlighting if correct responses
|
// Print the text by the control highlighting if correct responses
|
||||||
// should be shown and the current answer is the correct answer in
|
// should be shown and the current answer is the correct answer in
|
||||||
// the single selection case or has a positive score in the multiple
|
// the single selection case or has a positive score in the multiple
|
||||||
// selection case
|
// selection case
|
||||||
if ($options->readonly && $options->correct_responses &&
|
$a->class = ($options->readonly && $options->correct_responses &&
|
||||||
is_array($correctanswers) && in_array($aid, $correctanswers)) {
|
is_array($correctanswers) && in_array($aid, $correctanswers)) ?
|
||||||
echo '<td valign="top" class="highlight"><label for="'.$id.'">'.
|
'highlight' : '';
|
||||||
format_text("$qnumchar. $answer->answer", FORMAT_MOODLE ,
|
|
||||||
$formatoptions) . '</label></td>';
|
|
||||||
} else {
|
|
||||||
echo '<td valign="top"><label for="'.$id.'">'.
|
|
||||||
format_text("$qnumchar. $answer->answer", FORMAT_MOODLE,
|
|
||||||
$formatoptions) . '</label></td>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print feedback by selected options if feedback is on
|
// Print the answer text
|
||||||
if (($options->feedback || $options->correct_responses) &&
|
$a->text = format_text("$qnumchar. $answer->answer", FORMAT_MOODLE, $formatoptions);
|
||||||
$checked) {
|
|
||||||
echo '<td valign="top">';
|
|
||||||
quiz_print_comment($answer->feedback);
|
|
||||||
echo '</td>';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '</tr>';
|
// 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 '</table>';
|
include("$CFG->dirroot/mod/quiz/questiontypes/multichoice/display.html");
|
||||||
echo '</td></tr></table>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function grade_responses(&$question, &$state, $cmoptions) {
|
function grade_responses(&$question, &$state, $cmoptions) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue