Merge branch 'MDL-79937_fixlessonmatching' of https://github.com/catalystfd/moodle

This commit is contained in:
Ilya Tregubov 2024-01-08 09:19:39 +08:00
commit 4179fa2dfc

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)) {