diff --git a/question/type/multichoice/question.php b/question/type/multichoice/question.php index bf9b43c6657..fffe0be1c41 100644 --- a/question/type/multichoice/question.php +++ b/question/type/multichoice/question.php @@ -162,10 +162,9 @@ abstract class qtype_multichoice_base extends question_graded_automatically { break; } } - // Param $options->suppresschoicefeedback is a hack specific to the - // oumultiresponse question type. It would be good to refactor to - // avoid refering to it here. - return $options->feedback && empty($options->suppresschoicefeedback) && + qtype_multichoice::support_legacy_review_options_hack($options); + return $options->feedback && + $options->feedback !== qtype_multichoice::COMBINED_BUT_NOT_CHOICE_FEEDBACK && $isselected; } else if ($component == 'question' && $filearea == 'hint') { diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index 08b743444cf..b1d1b4ff0cf 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -37,6 +37,35 @@ require_once($CFG->libdir . '/questionlib.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class qtype_multichoice extends question_type { + /** + * @var int a special value that can be set for {@see question_display_options::$feedback}. + * + * This is not used by the core question type, but is used by some variants of this question + * types in the plugins database, including qtype_oumultiresponse and qtype_answersselect. + * + * If ->feedback is set to this value, then the renderer will display the combined feebdack, + * but not the feedback for each specific choice. + */ + const COMBINED_BUT_NOT_CHOICE_FEEDBACK = 0x100; + + /** + * Helper to catch and update if a plugin is using the old version of the COMBINED_BUT_NOT_CHOICE_FEEDBACK thing. + * + * @param question_display_options $options to be updated before being used. + */ + public static function support_legacy_review_options_hack(question_display_options $options): void { + if (empty($options->suppresschoicefeedback)) { + return; // Nothing to do. + } + + debugging('$options->suppresschoicefeedback should no longer be used. To get a similar effect, ' . + 'instead set $options->feedback = $options->feedback && qtype_multichoice::COMBINED_BUT_NOT_CHOICE_FEEDBACK.'); + if ($options->feedback) { + $options->feedback = self::COMBINED_BUT_NOT_CHOICE_FEEDBACK; + } + unset($options->suppresschoicefeedback); + } + public function get_question_options($question) { global $DB, $OUTPUT; diff --git a/question/type/multichoice/renderer.php b/question/type/multichoice/renderer.php index 287ca32162d..047af849ec4 100644 --- a/question/type/multichoice/renderer.php +++ b/question/type/multichoice/renderer.php @@ -57,7 +57,7 @@ abstract class qtype_multichoice_renderer_base extends qtype_with_combined_feedb /** * Whether a choice should be considered right, wrong or partially right. * @param question_answer $ans representing one of the choices. - * @return fload 1.0, 0.0 or something in between, respectively. + * @return float 1.0, 0.0 or something in between, respectively. */ protected abstract function is_right(question_answer $ans); @@ -118,10 +118,8 @@ abstract class qtype_multichoice_renderer_base extends qtype_with_combined_feedb 'data-region' => 'answer-label', ]); - // Param $options->suppresschoicefeedback is a hack specific to the - // oumultiresponse question type. It would be good to refactor to - // avoid refering to it here. - if ($options->feedback && empty($options->suppresschoicefeedback) && + qtype_multichoice::support_legacy_review_options_hack($options); + if ($options->feedback && $options->feedback !== qtype_multichoice::COMBINED_BUT_NOT_CHOICE_FEEDBACK && $isselected && trim($ans->feedback)) { $feedback[] = html_writer::tag('div', $question->make_html_inline($question->format_text(