MDL-24408 extra_question_fields: separate answer data creation code

Now any question using extra_question_fields can overload make_answer
(just as make_hint), instead of overloading whole initialise_question_answers.
This commit is contained in:
Oleg Sychev 2014-01-25 00:23:34 +03:00
parent f0c6c18189
commit 92e83e2d0e

View file

@ -950,14 +950,24 @@ class question_type {
return;
}
foreach ($questiondata->options->answers as $a) {
$question->answers[$a->id] = new question_answer($a->id, $a->answer,
$a->fraction, $a->feedback, $a->feedbackformat);
$question->answers[$a->id] = $this->make_answer($a);
if (!$forceplaintextanswers) {
$question->answers[$a->id]->answerformat = $a->answerformat;
}
}
}
/**
* Create a question_answer, or an appropriate subclass for this question,
* from a row loaded from the database.
* @param object $answer the DB row from the question_answers table plus extra answer fields.
* @return question_answer
*/
protected function make_answer($answer) {
return new question_answer($answer->id, $answer->answer,
$answer->fraction, $answer->feedback, $answer->feedbackformat);
}
/**
* Deletes the question-type specific data when a question is deleted.
* @param int $question the question being deleted.