Skip to content

Commit

Permalink
MDL-39488 Lesson Module: Fix for "Match question throws PHP error if …
Browse files Browse the repository at this point in the history
…one or more options have not been selected "

Signed-off-by: Joseph Rézeau <moodle@rezeau.org>
  • Loading branch information
Joseph Rézeau authored and Rossiani Wijaya committed May 8, 2013
1 parent 43ded67 commit eff3864
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions mod/lesson/pagetypes/matching.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -161,7 +161,15 @@ public function check_answer() {
} }


$response = $data->response; $response = $data->response;
if (!is_array($response)) { $empty = 0;
foreach ($response as $resp) {
if ($resp != '') {
break;
} else {
$empty ++;
}
}
if ($empty == count($response)) {
$result->noanswer = true; $result->noanswer = true;
return $result; return $result;
} }
Expand All @@ -177,13 +185,13 @@ public function check_answer() {
} }
unset($answers[$key]); unset($answers[$key]);
} }
// get he users exact responses for record keeping // get the user's exact responses for record keeping
$hits = 0; $hits = 0;
$userresponse = array(); $userresponse = array();
foreach ($response as $id => $value) { foreach ($response as $id => $value) {
$userresponse[] = $value; $userresponse[] = $value;
// Make sure the user's answer is exist in question's answer // Make sure the user's answer exists in question's answer
if (array_key_exists($id, $answers)) { if (array_key_exists($id, $answers) && $value) {
$answer = $answers[$id]; $answer = $answers[$id];
$result->studentanswer .= '<br />'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$answers[$value]->response; $result->studentanswer .= '<br />'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$answers[$value]->response;
if ($id == $value) { if ($id == $value) {
Expand Down

0 comments on commit eff3864

Please sign in to comment.