mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-34050 Lesson Module: improved matching question logic for checking user response. This patch will also resolved MDL-36343.
This commit is contained in:
parent
fcb88d7d6d
commit
2e48a42419
1 changed files with 18 additions and 17 deletions
|
@ -72,16 +72,18 @@ class lesson_page_type_matching extends lesson_page {
|
||||||
foreach ($answers as $answer) {
|
foreach ($answers as $answer) {
|
||||||
// get all the response
|
// get all the response
|
||||||
if ($answer->response != NULL) {
|
if ($answer->response != NULL) {
|
||||||
$responses[] = trim($answer->response);
|
$responses[$answer->id] = trim($answer->response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$responseoptions = array(''=>get_string('choosedots'));
|
$responseoptions = array(''=>get_string('choosedots'));
|
||||||
if (!empty($responses)) {
|
if (!empty($responses)) {
|
||||||
shuffle($responses);
|
$shuffleresponses = $responses;
|
||||||
$responses = array_unique($responses);
|
shuffle($shuffleresponses);
|
||||||
foreach ($responses as $response) {
|
$shuffleresponses = array_unique($shuffleresponses);
|
||||||
$responseoptions[htmlspecialchars(trim($response))] = $response;
|
foreach ($shuffleresponses as $response) {
|
||||||
|
$key = array_search($response, $responses);
|
||||||
|
$responseoptions[$key] = $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($USER->modattempts[$this->lesson->id]) && !empty($attempt->useranswer)) {
|
if (isset($USER->modattempts[$this->lesson->id]) && !empty($attempt->useranswer)) {
|
||||||
|
@ -171,27 +173,26 @@ class lesson_page_type_matching extends lesson_page {
|
||||||
$wrong = array_shift($answers);
|
$wrong = array_shift($answers);
|
||||||
|
|
||||||
foreach ($answers as $key=>$answer) {
|
foreach ($answers as $key=>$answer) {
|
||||||
if ($answer->answer === '' or $answer->response === '') {
|
if ($answer->answer !== '' or $answer->response !== '') {
|
||||||
// incomplete option!
|
$answers[$answer->id] = $answer;
|
||||||
unset($answers[$key]);
|
|
||||||
}
|
}
|
||||||
|
unset($answers[$key]);
|
||||||
}
|
}
|
||||||
// get he users exact responses for record keeping
|
// get he users exact responses for record keeping
|
||||||
$hits = 0;
|
$hits = 0;
|
||||||
$userresponse = array();
|
$userresponse = array();
|
||||||
foreach ($response as $key => $value) {
|
foreach ($response as $id => $value) {
|
||||||
foreach($answers as $answer) {
|
$userresponse[] = $value;
|
||||||
if ($value === $answer->response) {
|
// Make sure the user's answer is exist in question's answer
|
||||||
$userresponse[] = $answer->id;
|
if (array_key_exists($id, $answers)) {
|
||||||
}
|
$answer = $answers[$id];
|
||||||
if ((int)$answer->id === (int)$key) {
|
$result->studentanswer .= '<br />'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$answers[$value]->response;
|
||||||
$result->studentanswer .= '<br />'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$value;
|
if ($id == $value) {
|
||||||
}
|
|
||||||
if ((int)$answer->id === (int)$key and $value === $answer->response) {
|
|
||||||
$hits++;
|
$hits++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result->userresponse = implode(",", $userresponse);
|
$result->userresponse = implode(",", $userresponse);
|
||||||
|
|
||||||
if ($hits == count($answers)) {
|
if ($hits == count($answers)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue