MDL-24408 extra_answer_fields : get answers even if they miss extra data
Extra answer data may be optional, saving DB space - i.e. not every row in question_answers will have respective row in extra answers table. Current implementation of question_type::get_question_options() won't return such answers at all. This commit fix that, changing join type for db query. Also fixed coding style violation in the variable name in get_question_options.
This commit is contained in:
@@ -645,15 +645,17 @@ class question_type {
|
||||
|
||||
$extraanswerfields = $this->extra_answer_fields();
|
||||
if (is_array($extraanswerfields)) {
|
||||
$answer_extension_table = array_shift($extraanswerfields);
|
||||
$answerextensiontable = array_shift($extraanswerfields);
|
||||
// Use LEFT JOIN in case not every answer has extra data.
|
||||
$question->options->answers = $DB->get_records_sql("
|
||||
SELECT qa.*, qax." . implode(', qax.', $extraanswerfields) . "
|
||||
FROM {question_answers} qa, {{$answer_extension_table}} qax
|
||||
WHERE qa.question = ? AND qax.answerid = qa.id
|
||||
SELECT qa.*, qax." . implode(', qax.', $extraanswerfields) . '
|
||||
FROM {question_answers} qa ' . "
|
||||
LEFT JOIN {{$answerextensiontable}} qax ON qa.id = qax.answerid
|
||||
WHERE qa.question = ?
|
||||
ORDER BY qa.id", array($question->id));
|
||||
if (!$question->options->answers) {
|
||||
echo $OUTPUT->notification('Failed to load question answers from the table ' .
|
||||
$answer_extension_table . 'for questionid ' . $question->id);
|
||||
$answerextensiontable . 'for questionid ' . $question->id);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user