MDL-20636 Review and fix the format parameter to all calls to format_text.

This commit is contained in:
Tim Hunt 2011-02-24 20:18:16 +00:00
parent a18fda20c4
commit 22cebed503
20 changed files with 100 additions and 69 deletions

View file

@ -1123,10 +1123,9 @@ class quiz_question_bank_view extends question_bank_view {
echo '<div class="categoryinfo"><div class="categorynamefieldcontainer">' . echo '<div class="categoryinfo"><div class="categorynamefieldcontainer">' .
$strcategory; $strcategory;
echo ': <span class="categorynamefield">'; echo ': <span class="categorynamefield">';
echo shorten_text(strip_tags(format_text($category->name, FORMAT_MOODLE, echo shorten_text(strip_tags(format_string($category->name)), 60);
$formatoptions, $this->course->id)), 60);
echo '</span></div><div class="categoryinfofieldcontainer"><span class="categoryinfofield">'; echo '</span></div><div class="categoryinfofieldcontainer"><span class="categoryinfofield">';
echo shorten_text(strip_tags(format_text($category->info, FORMAT_MOODLE, echo shorten_text(strip_tags(format_text($category->info, $category->infoformat,
$formatoptions, $this->course->id)), 200); $formatoptions, $this->course->id)), 200);
echo '</span></div></div>'; echo '</span></div></div>';
} }

View file

@ -1220,7 +1220,7 @@ class question_bank_view {
$formatoptions->noclean = true; $formatoptions->noclean = true;
$formatoptions->overflowdiv = true; $formatoptions->overflowdiv = true;
echo '<div class="boxaligncenter">'; echo '<div class="boxaligncenter">';
echo format_text($category->info, FORMAT_MOODLE, $formatoptions, $this->course->id); echo format_text($category->info, $category->infoformat, $formatoptions, $this->course->id);
echo "</div>\n"; echo "</div>\n";
} }

View file

@ -113,6 +113,8 @@ class test_question_maker {
$tf->rightanswer = true; $tf->rightanswer = true;
$tf->truefeedback = 'This is the right answer.'; $tf->truefeedback = 'This is the right answer.';
$tf->falsefeedback = 'This is the wrong answer.'; $tf->falsefeedback = 'This is the wrong answer.';
$tf->truefeedbackformat = FORMAT_HTML;
$tf->falsefeedbackformat = FORMAT_HTML;
$tf->trueanswerid = 13; $tf->trueanswerid = 13;
$tf->falseanswerid = 14; $tf->falseanswerid = 14;
@ -193,10 +195,13 @@ class test_question_maker {
self::set_standard_combined_feedback_fields($match); self::set_standard_combined_feedback_fields($match);
// Using unset to get 1-based arrays.
$match->stems = array('', 'Dog', 'Frog', 'Toad', 'Cat'); $match->stems = array('', 'Dog', 'Frog', 'Toad', 'Cat');
$match->stemformat = array('', FORMAT_HTML, FORMAT_HTML, FORMAT_HTML, FORMAT_HTML);
$match->choices = array('', 'Mammal', 'Amphibian', 'Insect'); $match->choices = array('', 'Mammal', 'Amphibian', 'Insect');
$match->right = array('', 1, 2, 2, 1); $match->right = array('', 1, 2, 2, 1);
unset($match->stems[0]); unset($match->stems[0]);
unset($match->stemformat[0]);
unset($match->choices[0]); unset($match->choices[0]);
unset($match->right[0]); unset($match->right[0]);

View file

@ -846,14 +846,8 @@ class qformat_default {
global $DB; global $DB;
$formatoptions = new stdClass(); $formatoptions = new stdClass();
$formatoptions->noclean = true; $formatoptions->noclean = true;
$formatoptions->para = false; return html_to_text(format_text($question->questiontext,
if (empty($question->questiontextformat)) { $this->questiontextformat, $formatoptions), 0, false);
$format = FORMAT_MOODLE;
} else {
$format = $question->questiontextformat;
}
$text = $question->questiontext;
return format_text(html_to_text($text, 0, false), $format, $formatoptions);
} }
/** /**

View file

@ -67,11 +67,9 @@ function writequestion($question) {
// add header // add header
$expout .= "<h3>$question->name</h3>\n"; $expout .= "<h3>$question->name</h3>\n";
// format and add question text // Format and add the question text
$questiontext = $question->questiontext; $expout .= '<p class="questiontext">' . format_text($question->questiontext,
$format = $question->questiontextformat; $question->questiontextformat); . "</p>\n";
$formatted_text = format_text($questiontext, $format);
$expout .= "<p class=\"questiontext\">$formatted_text</p>\n";
// selection depends on question type // selection depends on question type
switch($question->qtype) { switch($question->qtype) {

View file

@ -97,12 +97,12 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical
} }
public function get_question_summary() { public function get_question_summary() {
$question = $this->html_to_text($this->questiontext); $question = $this->html_to_text($this->questiontext, $this->questiontextformat);
$groups = array(); $groups = array();
foreach ($this->choices as $group => $choices) { foreach ($this->choices as $group => $choices) {
$cs = array(); $cs = array();
foreach ($choices as $choice) { foreach ($choices as $choice) {
$cs[] = $this->html_to_text($choice->text); $cs[] = html_to_text($choice->text, 0, false);
} }
$groups[] = '[[' . $group . ']] -> {' . implode(' / ', $cs) . '}'; $groups[] = '[[' . $group . ']] -> {' . implode(' / ', $cs) . '}';
} }
@ -120,8 +120,8 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical
foreach ($this->places as $place => $group) { foreach ($this->places as $place => $group) {
if (array_key_exists($this->field($place), $response) && if (array_key_exists($this->field($place), $response) &&
$response[$this->field($place)]) { $response[$this->field($place)]) {
$choices[] = '{' . $this->html_to_text($this->get_selected_choice( $choices[] = '{' . html_to_text($this->get_selected_choice(
$group, $response[$this->field($place)])->text) . '}'; $group, $response[$this->field($place)])->text, 0, false) . '}';
$allblank = false; $allblank = false;
} else { } else {
$choices[] = '{}'; $choices[] = '{}';
@ -286,7 +286,7 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical
$choiceno = $this->choiceorder[$group][$response[$fieldname]]; $choiceno = $this->choiceorder[$group][$response[$fieldname]];
$choice = $this->choices[$group][$choiceno]; $choice = $this->choices[$group][$choiceno];
$parts[$place] = new question_classified_response( $parts[$place] = new question_classified_response(
$choiceno, $this->html_to_text($choice->text), $choiceno, html_to_text($choice->text, 0, false),
$this->get_right_choice_for($place) == $response[$fieldname]); $this->get_right_choice_for($place) == $response[$fieldname]);
} }
return $parts; return $parts;

View file

@ -297,7 +297,7 @@ abstract class qtype_gapselect_base extends question_type {
foreach ($question->choices[$group] as $i => $choice) { foreach ($question->choices[$group] as $i => $choice) {
$choices[$i] = new question_possible_response( $choices[$i] = new question_possible_response(
$question->html_to_text($choice->text), html_to_text($choice->text, 0, false),
$question->rightchoices[$place] == $i); $question->rightchoices[$place] == $i);
} }
$choices[null] = question_possible_response::no_response(); $choices[null] = question_possible_response::no_response();

View file

@ -51,7 +51,7 @@ abstract class qtype_elements_embedded_in_question_text_renderer extends qtype_w
$result = ''; $result = '';
$result .= html_writer::tag('div', $question->format_text($questiontext, $result .= html_writer::tag('div', $question->format_text($questiontext,
$qa, 'question', 'questiontext', $question->id), $question->questiontextformat, $qa, 'question', 'questiontext', $question->id),
array('class' => $this->qtext_classname(), 'id' => $qa->get_qt_field_name(''))); array('class' => $this->qtext_classname(), 'id' => $qa->get_qt_field_name('')));
$result .= $this->post_qtext_elements($qa, $options); $result .= $this->post_qtext_elements($qa, $options);

View file

@ -88,10 +88,10 @@ class qtype_match_question extends question_graded_automatically_with_countback
} }
public function get_question_summary() { public function get_question_summary() {
$question = $this->html_to_text($this->questiontext); $question = $this->html_to_text($this->questiontext, $this->questiontextformat);
$stems = array(); $stems = array();
foreach ($this->stemorder as $stemid) { foreach ($this->stemorder as $stemid) {
$stems[] = $this->html_to_text($this->stems[$stemid]); $stems[] = $this->html_to_text($this->stems[$stemid], $this->stemformat[$stemid]);
} }
$choices = array(); $choices = array();
foreach ($this->choiceorder as $choiceid) { foreach ($this->choiceorder as $choiceid) {
@ -105,8 +105,8 @@ class qtype_match_question extends question_graded_automatically_with_countback
$matches = array(); $matches = array();
foreach ($this->stemorder as $key => $stemid) { foreach ($this->stemorder as $key => $stemid) {
if (array_key_exists($this->field($key), $response) && $response[$this->field($key)]) { if (array_key_exists($this->field($key), $response) && $response[$this->field($key)]) {
$matches[] = $this->html_to_text($this->stems[$stemid]) . ' -> ' . $matches[] = $this->html_to_text($this->stems[$stemid], $this->stemformat[$stemid]) .
$this->choices[$this->choiceorder[$response[$this->field($key)]]]; ' -> ' . $this->choices[$this->choiceorder[$response[$this->field($key)]]];
} }
} }
if (empty($matches)) { if (empty($matches)) {

View file

@ -149,6 +149,7 @@ class qtype_match extends question_type {
if ($matchsub->questiontext !== '') { if ($matchsub->questiontext !== '') {
$question->stems[$matchsub->id] = $matchsub->questiontext; $question->stems[$matchsub->id] = $matchsub->questiontext;
$question->stemformat[$matchsub->id] = $matchsub->questiontextformat;
$question->right[$matchsub->id] = $key; $question->right[$matchsub->id] = $key;
} }
} }
@ -181,7 +182,7 @@ class qtype_match extends question_type {
$responses = array(); $responses = array();
foreach ($q->choices as $choiceid => $choice) { foreach ($q->choices as $choiceid => $choice) {
$responses[$choiceid] = new question_possible_response( $responses[$choiceid] = new question_possible_response(
$q->html_to_text($stem) . ': ' . $q->html_to_text($choice), $q->html_to_text($stem, $q->stemformat[$stemid]) . ': ' . $choice,
($choiceid == $q->right[$stemid]) / count($q->stems)); ($choiceid == $q->right[$stemid]) / count($q->stems));
} }
$responses[null] = question_possible_response::no_response(); $responses[null] = question_possible_response::no_response();

View file

@ -59,7 +59,8 @@ class qtype_match_renderer extends qtype_with_combined_feedback_renderer {
$result .= html_writer::start_tag('tr', array('class' => 'r' . $parity)); $result .= html_writer::start_tag('tr', array('class' => 'r' . $parity));
$fieldname = 'sub' . $key; $fieldname = 'sub' . $key;
$result .= html_writer::tag('td', $question->format_text($question->stems[$stemid], $result .= html_writer::tag('td', $question->format_text(
$question->stems[$stemid], $question->stemformat[$stemid],
$qa, 'qtype_match', 'subquestion', $stemid), $qa, 'qtype_match', 'subquestion', $stemid),
array('class' => 'text')); array('class' => 'text'));
@ -120,7 +121,8 @@ class qtype_match_renderer extends qtype_with_combined_feedback_renderer {
$choices = $this->format_choices($question); $choices = $this->format_choices($question);
$right = array(); $right = array();
foreach ($stemorder as $key => $stemid) { foreach ($stemorder as $key => $stemid) {
$right[] = $question->format_text($question->stems[$stemid], $qa, $right[] = $question->format_text($question->stems[$stemid],
$question->stemformat[$stemid], $qa,
'qtype_match', 'subquestion', $stemid) . ' ' . 'qtype_match', 'subquestion', $stemid) . ' ' .
$choices[$question->get_right_choice_for($stemid)]; $choices[$question->get_right_choice_for($stemid)];
} }

View file

@ -76,10 +76,26 @@ class qtype_match_test extends UnitTestCase {
test_question_maker::set_standard_combined_feedback_fields($q->options); test_question_maker::set_standard_combined_feedback_fields($q->options);
$q->options->subquestions = array( $q->options->subquestions = array(
14 => (object) array('id' => 14, 'questiontext' => 'frog', 'answertext' => 'amphibian'), 14 => (object) array(
15 => (object) array('id' => 15, 'questiontext' => 'cat', 'answertext' => 'mammal'), 'id' => 14,
16 => (object) array('id' => 16, 'questiontext' => 'newt', 'answertext' => 'amphibian'), 'questiontext' => 'frog',
17 => (object) array('id' => 17, 'questiontext' => '', 'answertext' => 'insect'), 'questiontextformat' => FORMAT_HTML,
'answertext' => 'amphibian'),
15 => (object) array(
'id' => 15,
'questiontext' => 'cat',
'questiontextformat' => FORMAT_HTML,
'answertext' => 'mammal'),
16 => (object) array(
'id' => 16,
'questiontext' => 'newt',
'questiontextformat' => FORMAT_HTML,
'answertext' => 'amphibian'),
17 => (object) array(
'id' => 17,
'questiontext' => '',
'questiontextformat' => FORMAT_HTML,
'answertext' => 'insect'),
); );
return $q; return $q;

View file

@ -68,10 +68,11 @@ abstract class qtype_multichoice_base extends question_graded_automatically {
} }
public function get_question_summary() { public function get_question_summary() {
$question = $this->html_to_text($this->questiontext); $question = $this->html_to_text($this->questiontext, $this->questiontextformat);
$choices = array(); $choices = array();
foreach ($this->order as $ansid) { foreach ($this->order as $ansid) {
$choices[] = $this->html_to_text($this->answers[$ansid]->answer); $choices[] = $this->html_to_text($this->answers[$ansid]->answer,
$this->answers[$ansid]->answerformat);
} }
return $question . ': ' . implode('; ', $choices); return $question . ': ' . implode('; ', $choices);
} }
@ -157,7 +158,8 @@ class qtype_multichoice_single_question extends qtype_multichoice_base {
return null; return null;
} }
$ansid = $this->order[$response['answer']]; $ansid = $this->order[$response['answer']];
return $this->html_to_text($this->answers[$ansid]->answer); return $this->html_to_text($this->answers[$ansid]->answer,
$this->answers[$ansid]->answerformat);
} }
public function classify_response(array $response) { public function classify_response(array $response) {
@ -168,7 +170,7 @@ class qtype_multichoice_single_question extends qtype_multichoice_base {
$choiceid = $this->order[$response['answer']]; $choiceid = $this->order[$response['answer']];
$ans = $this->answers[$choiceid]; $ans = $this->answers[$choiceid];
return array($this->id => new question_classified_response($choiceid, return array($this->id => new question_classified_response($choiceid,
$this->html_to_text($ans->answer), $ans->fraction)); $this->html_to_text($ans->answer, $ans->answerformat), $ans->fraction));
} }
public function get_correct_response() { public function get_correct_response() {
@ -283,7 +285,8 @@ class qtype_multichoice_multi_question extends qtype_multichoice_base {
foreach ($this->order as $key => $ans) { foreach ($this->order as $key => $ans) {
$fieldname = $this->field($key); $fieldname = $this->field($key);
if (array_key_exists($fieldname, $response) && $response[$fieldname]) { if (array_key_exists($fieldname, $response) && $response[$fieldname]) {
$selectedchoices[] = $this->html_to_text($this->answers[$ans]->answer); $selectedchoices[] = $this->html_to_text($this->answers[$ans]->answer,
$this->answers[$ans]->answerformat);
} }
} }
if (empty($selectedchoices)) { if (empty($selectedchoices)) {
@ -304,7 +307,7 @@ class qtype_multichoice_multi_question extends qtype_multichoice_base {
foreach ($this->answers as $ansid => $ans) { foreach ($this->answers as $ansid => $ans) {
if (isset($selectedchoices[$ansid])) { if (isset($selectedchoices[$ansid])) {
$choices[$ansid] = new question_classified_response($ansid, $choices[$ansid] = new question_classified_response($ansid,
$this->html_to_text($ans->answer), $ans->fraction); $this->html_to_text($ans->answer, $ans->answerformat), $ans->fraction);
} }
} }
return $choices; return $choices;

View file

@ -95,8 +95,8 @@ abstract class qtype_multichoice_renderer_base extends qtype_with_combined_feedb
} }
$radiobuttons[] = $hidden . html_writer::empty_tag('input', $inputattributes) . $radiobuttons[] = $hidden . html_writer::empty_tag('input', $inputattributes) .
html_writer::tag('label', $this->number_in_style($value, $question->answernumbering) . html_writer::tag('label', $this->number_in_style($value, $question->answernumbering) .
$question->format_text($ans->answer, $qa, $question->format_text($ans->answer, $ans->answerformat,
'question', 'answer', $ansid), array('for' => $inputattributes['id'])); $qa, 'question', 'answer', $ansid), array('for' => $inputattributes['id']));
// $options->suppresschoicefeedback is a hack specific to the // $options->suppresschoicefeedback is a hack specific to the
// oumultiresponse question type. It would be good to refactor to // oumultiresponse question type. It would be good to refactor to
@ -104,7 +104,8 @@ abstract class qtype_multichoice_renderer_base extends qtype_with_combined_feedb
if ($options->feedback && empty($options->suppresschoicefeedback) && if ($options->feedback && empty($options->suppresschoicefeedback) &&
$isselected && trim($ans->feedback)) { $isselected && trim($ans->feedback)) {
$feedback[] = html_writer::tag('div', $feedback[] = html_writer::tag('div',
$question->format_text($ans->feedback, $qa, 'question', 'answerfeedback', $ansid), $question->format_text($ans->feedback, $ans->feedbackformat,
$qa, 'question', 'answerfeedback', $ansid),
array('class' => 'specificfeedback')); array('class' => 'specificfeedback'));
} else { } else {
$feedback[] = ''; $feedback[] = '';
@ -224,7 +225,8 @@ class qtype_multichoice_single_renderer extends qtype_multichoice_renderer_base
if (question_state::graded_state_for_fraction($ans->fraction) == if (question_state::graded_state_for_fraction($ans->fraction) ==
question_state::$gradedright) { question_state::$gradedright) {
return get_string('correctansweris', 'qtype_multichoice', return get_string('correctansweris', 'qtype_multichoice',
$question->format_text($ans->answer, $qa, 'question', 'answer', $ansid)); $question->format_text($ans->answer, $ans->answerformat,
$qa, 'question', 'answer', $ansid));
} }
} }
@ -274,7 +276,8 @@ class qtype_multichoice_multi_renderer extends qtype_multichoice_renderer_base {
$right = array(); $right = array();
foreach ($question->answers as $ansid => $ans) { foreach ($question->answers as $ansid => $ans) {
if ($ans->fraction > 0) { if ($ans->fraction > 0) {
$right[] = $question->format_text($ans->answer, $qa, 'question', 'answer', $ansid); $right[] = $question->format_text($ans->answer, $ans->answerformat,
$qa, 'question', 'answer', $ansid);
} }
} }

View file

@ -188,7 +188,7 @@ abstract class question_definition {
* @return string|null a plain text summary of this question. * @return string|null a plain text summary of this question.
*/ */
public function get_question_summary() { public function get_question_summary() {
return $this->html_to_text($this->questiontext); return $this->html_to_text($this->questiontext, $this->questiontextformat);
} }
/** /**
@ -256,6 +256,7 @@ abstract class question_definition {
* this question. * this question.
* *
* @param string $text some content that needs to be output. * @param string $text some content that needs to be output.
* @param int $format the FORMAT_... constant.
* @param question_attempt $qa the question attempt. * @param question_attempt $qa the question attempt.
* @param string $component used for rewriting file area URLs. * @param string $component used for rewriting file area URLs.
* @param string $filearea used for rewriting file area URLs. * @param string $filearea used for rewriting file area URLs.
@ -263,37 +264,37 @@ abstract class question_definition {
* parts of the question do not need to be cleaned, and student input does. * parts of the question do not need to be cleaned, and student input does.
* @return string the text formatted for output by format_text. * @return string the text formatted for output by format_text.
*/ */
public function format_text($text, $qa, $component, $filearea, $itemid, $clean = false) { public function format_text($text, $format, $qa, $component, $filearea, $itemid, $clean = false) {
// TODO format.
$formatoptions = new stdClass(); $formatoptions = new stdClass();
$formatoptions->noclean = !$clean; $formatoptions->noclean = !$clean;
$formatoptions->para = false; $formatoptions->para = false;
$text = $qa->rewrite_pluginfile_urls($text, $component, $filearea, $itemid); $text = $qa->rewrite_pluginfile_urls($text, $component, $filearea, $itemid);
return format_text($text, $this->questiontextformat, $formatoptions); return format_text($text, $format, $formatoptions);
} }
/** /**
* Convert some part of the question text to plain text. This might be used, * Convert some part of the question text to plain text. This might be used,
* for example, by get_response_summary(). * for example, by get_response_summary().
* @param string $text The HTML to reduce to plain text. * @param string $text The HTML to reduce to plain text.
* @param int $format the FORMAT_... constant.
* @return string the equivalent plain text.
*/ */
public function html_to_text($text) { public function html_to_text($text, $format) {
$formatoptions = new stdClass(); $formatoptions = new stdClass();
$formatoptions->noclean = true; $formatoptions->noclean = true;
return html_to_text(format_text($text, $this->questiontextformat, $formatoptions), return html_to_text(format_text($text, $format, $formatoptions), 0, false);
0, false);
} }
/** @return the result of applying {@link format_text()} to the question text. */ /** @return the result of applying {@link format_text()} to the question text. */
public function format_questiontext($qa) { public function format_questiontext($qa) {
return $this->format_text($this->questiontext, $qa, return $this->format_text($this->questiontext, $this->questiontextformat,
'question', 'questiontext', $this->id); $qa, 'question', 'questiontext', $this->id);
} }
/** @return the result of applying {@link format_text()} to the general feedback. */ /** @return the result of applying {@link format_text()} to the general feedback. */
public function format_generalfeedback($qa) { public function format_generalfeedback($qa) {
return $this->format_text($this->generalfeedback, $qa, return $this->format_text($this->generalfeedback, $this->generalfeedbackformat,
'question', 'generalfeedback', $this->id); $qa, 'question', 'generalfeedback', $this->id);
} }
/** /**
@ -600,7 +601,7 @@ abstract class question_graded_automatically extends question_with_responses
} }
public function format_hint(question_hint $hint, question_attempt $qa) { public function format_hint(question_hint $hint, question_attempt $qa) {
return $this->format_text($hint->hint, $qa, 'question', 'hint', $hint->id); return $this->format_text($hint->hint, $hint->hintformat, $qa, 'question', 'hint', $hint->id);
} }
} }
@ -707,6 +708,9 @@ class question_answer {
/** @var string the answer. */ /** @var string the answer. */
public $answer; public $answer;
/** @var integer one of the FORMAT_... constans. */
public $answerformat = FORMAT_PLAIN;
/** @var number the fraction this answer is worth. */ /** @var number the fraction this answer is worth. */
public $fraction; public $fraction;
@ -718,9 +722,12 @@ class question_answer {
/** /**
* Constructor. * Constructor.
* @param int $id the answer.
* @param string $answer the answer. * @param string $answer the answer.
* @param int $answerformat the format of the answer.
* @param number $fraction the fraction this answer is worth. * @param number $fraction the fraction this answer is worth.
* @param string $feedback the feedback for this answer. * @param string $feedback the feedback for this answer.
* @param int $feedbackformat the format of the feedback.
*/ */
public function __construct($id, $answer, $fraction, $feedback, $feedbackformat) { public function __construct($id, $answer, $fraction, $feedback, $feedbackformat) {
$this->id = $id; $this->id = $id;

View file

@ -37,7 +37,7 @@ require_once($CFG->dirroot . '/question/engine/lib.php');
* for, and the circumstances under which you might need to override it. * for, and the circumstances under which you might need to override it.
* *
* Note: the questiontype API should NOT be considered stable yet. Very few * Note: the questiontype API should NOT be considered stable yet. Very few
* question tyeps have been produced yet, so we do not yet know all the places * question types have been produced yet, so we do not yet know all the places
* where the current API is insufficient. I would rather learn from the * where the current API is insufficient. I would rather learn from the
* experiences of the first few question type implementors, and improve the * experiences of the first few question type implementors, and improve the
* interface to meet their needs, rather the freeze the API prematurely and * interface to meet their needs, rather the freeze the API prematurely and

View file

@ -252,10 +252,11 @@ abstract class qtype_with_combined_feedback_renderer extends qtype_renderer {
} }
$feedback = ''; $feedback = '';
$feedbackfield = $state->get_feedback_class() . 'feedback'; $field = $state->get_feedback_class() . 'feedback';
if ($question->$feedbackfield) { $format = $state->get_feedback_class() . 'feedbackformat';
$feedback .= $question->format_text($question->$feedbackfield, $qa, if ($question->$field) {
'question', $feedbackfield, $question->id); $feedback .= $question->format_text($question->$field, $question->$format,
$qa, 'question', $field, $question->id);
} }
return $feedback; return $feedback;

View file

@ -106,8 +106,8 @@ class qtype_shortanswer_renderer extends qtype_renderer {
return ''; return '';
} }
return $question->format_text($answer->feedback, $qa, return $question->format_text($answer->feedback, $answer->feedbackformat,
'question', 'answerfeedback', $answer->id); $qa, 'question', 'answerfeedback', $answer->id);
} }
public function correct_response(question_attempt $qa) { public function correct_response(question_attempt $qa) {

View file

@ -137,6 +137,8 @@ class qtype_truefalse extends question_type {
} }
$question->truefeedback = $answers[$questiondata->options->trueanswer]->feedback; $question->truefeedback = $answers[$questiondata->options->trueanswer]->feedback;
$question->falsefeedback = $answers[$questiondata->options->falseanswer]->feedback; $question->falsefeedback = $answers[$questiondata->options->falseanswer]->feedback;
$question->truefeedbackformat = $answers[$questiondata->options->trueanswer]->feedbackformat;
$question->falsefeedbackformat = $answers[$questiondata->options->falseanswer]->feedbackformat;
$question->trueanswerid = $questiondata->options->trueanswer; $question->trueanswerid = $questiondata->options->trueanswer;
$question->falseanswerid = $questiondata->options->falseanswer; $question->falseanswerid = $questiondata->options->falseanswer;
} }

View file

@ -127,11 +127,11 @@ class qtype_truefalse_renderer extends qtype_renderer {
$response = $qa->get_last_qt_var('answer', ''); $response = $qa->get_last_qt_var('answer', '');
if ($response) { if ($response) {
return $question->format_text($question->truefeedback, $qa, return $question->format_text($question->truefeedback, $question->truefeedbackformat,
'question', 'answerfeedback', $question->trueanswerid); $qa, 'question', 'answerfeedback', $question->trueanswerid);
} else { } else {
return $question->format_text($question->falsefeedback, $qa, return $question->format_text($question->falsefeedback, $question->falsefeedbackformat,
'question', 'answerfeedback', $question->falseanswerid); $qa, 'question', 'answerfeedback', $question->falseanswerid);
} }
} }