diff --git a/mod/lesson/pagetypes/matching.php b/mod/lesson/pagetypes/matching.php index 17c4531c917..930be9c588e 100644 --- a/mod/lesson/pagetypes/matching.php +++ b/mod/lesson/pagetypes/matching.php @@ -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)) {