Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix: Added missing <p> tags in renderer and update lang strings #2

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lang/en/qtype_oumatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
35 changes: 24 additions & 11 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(["<br>"], $right);
$correctanswers = "<br>" . implode("<br>", $right);
if (count($right) == 1) {
return get_string('correctansweris', 'qtype_oumatrix',
implode("<br>", $right));
} else if (count($right) > 1) {
return get_string('correctanswersare', 'qtype_oumatrix',
implode("<br>", $right));
return get_string('correctansweris', 'qtype_oumatrix', $correctanswers);
} else if (count($right) > 2) {
return get_string('correctanswersare', 'qtype_oumatrix', $correctanswers);
} else {
return "";
}
Expand Down Expand Up @@ -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));
}
}
}

/**
Expand Down Expand Up @@ -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();
Expand All @@ -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));
}
}
}
Loading