From fa745c75aaec808f0417be795595ecf275679470 Mon Sep 17 00:00:00 2001 From: Anupama Sarjoshi Date: Tue, 28 Nov 2023 12:34:56 +0000 Subject: [PATCH] Matrix: Added missing

tags in renderer and update lang strings --- lang/en/qtype_oumatrix.php | 10 +++++----- renderer.php | 35 ++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lang/en/qtype_oumatrix.php b/lang/en/qtype_oumatrix.php index 0a683f9..a8f9b8a 100644 --- a/lang/en/qtype_oumatrix.php +++ b/lang/en/qtype_oumatrix.php @@ -72,11 +72,11 @@ $string['shuffleanswers'] = 'Shuffle the items?'; $string['shuffleanswers_desc'] = 'Whether options should be randomly shuffled for each attempt by default.'; $string['shuffleanswers_help'] = 'If enabled, the order of the row items is randomly shuffled for each attempt, provided that "Shuffle within questions" in the activity settings is also enabled.'; -$string['toomanyanswercols'] = 'Matrix question type can have maximum {$a} answers columns'; -$string['toomanyquestionrows'] = 'Matrix question type can have maximum {$a} question rows'; +$string['toomanyanswercols'] = 'You can have maximum {$a} answer columns.'; +$string['toomanyquestionrows'] = 'You can have maximum {$a} sub-questions.'; $string['toomanyselected'] = 'You have selected too many options.'; $string['updateform'] = 'Update the response matrix'; $string['yougot1right'] = 'You have correctly selected one option.'; -$string['yougotnright'] = 'You have correctly selected {$a->num} options'; -$string['yougot1rightsubquestion'] = 'You have correctly answered one sub-question.'; -$string['yougotnrightsubquestion'] = 'You have correctly answered {$a->num} sub-questions.'; +$string['yougotnright'] = 'You have correctly selected {$a->num} options.'; +$string['yougot1rightsubquestion'] = 'You have correctly selected one row.'; +$string['yougotnrightsubquestion'] = 'You have correctly selected {$a->num} rows.'; diff --git a/renderer.php b/renderer.php index ba4da41..ef3bc1b 100644 --- a/renderer.php +++ b/renderer.php @@ -236,13 +236,11 @@ public function specific_feedback(question_attempt $qa) { */ protected function correct_choices(array $right): string { // Return appropriate string for single/multiple correct answer(s). - $right = array_merge(["
"], $right); + $correctanswers = "
" . implode("
", $right); if (count($right) == 1) { - return get_string('correctansweris', 'qtype_oumatrix', - implode("
", $right)); - } else if (count($right) > 1) { - return get_string('correctanswersare', 'qtype_oumatrix', - implode("
", $right)); + return get_string('correctansweris', 'qtype_oumatrix', $correctanswers); + } else if (count($right) > 2) { + return get_string('correctanswersare', 'qtype_oumatrix', $correctanswers); } else { return ""; } @@ -280,6 +278,21 @@ public function correct_response(question_attempt $qa) { } return $this->correct_choices($right); } + + protected function num_parts_correct(question_attempt $qa): string { + $a = new stdClass(); + list($a->num, $a->outof) = $qa->get_question()->get_num_parts_right( + $qa->get_last_qt_data()); + if (is_null($a->outof)) { + return ''; + } else if ($a->num == 1) { + return html_writer::tag('p', get_string('yougot1rightsubquestion', 'qtype_oumatrix')); + } else { + $f = new NumberFormatter(current_language(), NumberFormatter::SPELLOUT); + $a->num = $f->format($a->num); + return html_writer::tag('p', get_string('yougotnrightsubquestion', 'qtype_oumatrix', $a)); + } + } } /** @@ -325,7 +338,7 @@ public function correct_response(question_attempt $qa) { protected function num_parts_correct(question_attempt $qa): string { if ($qa->get_question()->get_num_selected_choices($qa->get_last_qt_data()) > $qa->get_question()->get_num_correct_choices()) { - return get_string('toomanyselected', 'qtype_oumatrix'); + return html_writer::tag('p', get_string('toomanyselected', 'qtype_oumatrix')); } $a = new stdClass(); @@ -335,22 +348,22 @@ protected function num_parts_correct(question_attempt $qa): string { return ''; } if ($a->num == 1) { - return get_string('yougot1rightsubquestion', 'qtype_oumatrix'); + return html_writer::tag('p', get_string('yougot1rightsubquestion', 'qtype_oumatrix')); } $f = new NumberFormatter(current_language(), NumberFormatter::SPELLOUT); $a->num = $f->format($a->num); - return get_string('yougotnrightsubquestion', 'qtype_oumatrix', $a); + return html_writer::tag('p', get_string('yougotnrightsubquestion', 'qtype_oumatrix', $a)); } else { list($a->num, $a->outof) = $qa->get_question()->get_num_parts_grade_partial($qa->get_last_qt_data()); if (is_null($a->outof)) { return ''; } if ($a->num == 1) { - return get_string('yougot1right', 'qtype_oumatrix'); + return html_writer::tag('p', get_string('yougot1right', 'qtype_oumatrix')); } $f = new NumberFormatter(current_language(), NumberFormatter::SPELLOUT); $a->num = $f->format($a->num); - return get_string('yougotnright', 'qtype_oumatrix', $a); + return html_writer::tag('p', get_string('yougotnright', 'qtype_oumatrix', $a)); } } }