MDL-79937 mod_lesson: Fix matching pagetype question matching

The addition of text format on the output of the answer responses broke
the matching later when comparing the valid answer against the sent
response, as the answer response was not correspondingly formatted.

I decided to use the un formatted answer response as the key, to keep it
as close as identical to prior behaviour
This commit is contained in:
Francis Devine
2023-12-08 09:08:06 +13:00
parent f72244a8c2
commit e368e04824
+9 -7
View File
@@ -79,19 +79,22 @@ class lesson_page_type_matching extends lesson_page {
$answers[$getanswer->id] = $getanswer;
}
// Calculate the text for the dropdown, keyed by the non formatted version.
$responses = array();
foreach ($answers as $answer) {
// get all the response
// Get all the response.
if ($answer->response != null) {
$responses[] = format_text(trim($answer->response));
$responses[trim($answer->response)] = format_text(trim($answer->response));
}
}
$responseoptions = array(''=>get_string('choosedots'));
// Now shuffle the answers to randomise the order of the items in the dropdown.
$responseoptions = ['' => get_string('choosedots')];
if (!empty($responses)) {
shuffle($responses);
foreach ($responses as $response) {
$responseoptions[htmlspecialchars($response, ENT_COMPAT)] = $response;
$keys = array_keys($responses);
shuffle($keys);
foreach ($keys as $key) {
$responseoptions[$key] = $responses[$key];
}
}
if (isset($USER->modattempts[$this->lesson->id]) && !empty($attempt->useranswer)) {
@@ -211,7 +214,6 @@ class lesson_page_type_matching extends lesson_page {
$result->noanswer = true;
return $result;
}
$value = htmlspecialchars_decode($value, ENT_COMPAT);
$userresponse[] = $value;
// Make sure the user's answer exists in question's answer
if (array_key_exists($id, $answers)) {