mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-50758 qtype_multichoice: Displays multiple correct answers
This commit is contained in:
parent
b8474fe0c7
commit
4358ee3892
2 changed files with 25 additions and 11 deletions
|
@ -37,6 +37,7 @@ $string['choiceno'] = 'Choice {$a}';
|
|||
$string['choices'] = 'Available choices';
|
||||
$string['clozeaid'] = 'Enter missing word';
|
||||
$string['correctansweris'] = 'The correct answer is: {$a}';
|
||||
$string['correctanswersare'] = 'The correct answers are: {$a}';
|
||||
$string['correctfeedback'] = 'For any correct response';
|
||||
$string['deletedchoice'] = 'This choice was deleted after the attempt was started.';
|
||||
$string['errgradesetanswerblank'] = 'Grade set, but the Answer is blank';
|
||||
|
|
|
@ -185,6 +185,24 @@ abstract class qtype_multichoice_renderer_base extends qtype_with_combined_feedb
|
|||
public function specific_feedback(question_attempt $qa) {
|
||||
return $this->combined_feedback($qa);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function returns string based on number of correct answers
|
||||
* @param array $right An Array of correct responses to the current question
|
||||
* @return string based on number of correct responses
|
||||
*/
|
||||
protected function correct_choices(array $right) {
|
||||
// Return appropriate string for single/multiple correct answer(s).
|
||||
if (count($right) == 1) {
|
||||
return get_string('correctansweris', 'qtype_multichoice',
|
||||
implode(', ', $right));
|
||||
} else if (count($right) > 1) {
|
||||
return get_string('correctanswersare', 'qtype_multichoice',
|
||||
implode(', ', $right));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -223,16 +241,16 @@ class qtype_multichoice_single_renderer extends qtype_multichoice_renderer_base
|
|||
public function correct_response(question_attempt $qa) {
|
||||
$question = $qa->get_question();
|
||||
|
||||
// Put all correct answers (100% grade) into $right.
|
||||
$right = array();
|
||||
foreach ($question->answers as $ansid => $ans) {
|
||||
if (question_state::graded_state_for_fraction($ans->fraction) ==
|
||||
question_state::$gradedright) {
|
||||
return get_string('correctansweris', 'qtype_multichoice',
|
||||
$question->make_html_inline($question->format_text($ans->answer, $ans->answerformat,
|
||||
$qa, 'question', 'answer', $ansid)));
|
||||
$right[] = $question->make_html_inline($question->format_text($ans->answer, $ans->answerformat,
|
||||
$qa, 'question', 'answer', $ansid));
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
return $this->correct_choices($right);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,12 +300,7 @@ class qtype_multichoice_multi_renderer extends qtype_multichoice_renderer_base {
|
|||
$qa, 'question', 'answer', $ansid));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($right)) {
|
||||
return get_string('correctansweris', 'qtype_multichoice',
|
||||
implode(', ', $right));
|
||||
}
|
||||
return '';
|
||||
return $this->correct_choices($right);
|
||||
}
|
||||
|
||||
protected function num_parts_correct(question_attempt $qa) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue