From 9705bfa84f5b22b3a2bc8862962fe51077675c8d Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Wed, 8 May 2013 11:49:45 +0800 Subject: [PATCH] MDL-39488 Lesson Module: Fixed PHP error matching question, if one or more options have not been selected. --- mod/lesson/lang/en/lesson.php | 2 +- mod/lesson/pagetypes/matching.php | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/mod/lesson/lang/en/lesson.php b/mod/lesson/lang/en/lesson.php index e7dd8aa361e..f2821d1edff 100644 --- a/mod/lesson/lang/en/lesson.php +++ b/mod/lesson/lang/en/lesson.php @@ -280,7 +280,7 @@ $string['nameapproved'] = 'Name approved'; $string['namereject'] = 'Sorry, your name has been rejected by the filter.
Please try another name.'; $string['new'] = 'new'; $string['nextpage'] = 'Next page'; -$string['noanswer'] = 'No answer given. Please go back and submit an answer.'; +$string['noanswer'] = 'One or more questions have no answer given. Please go back and submit an answer.'; $string['noattemptrecordsfound'] = 'No attempt records found: no grade given'; $string['nobranchtablefound'] = 'No content page found'; $string['nocommentyet'] = 'No comment yet.'; diff --git a/mod/lesson/pagetypes/matching.php b/mod/lesson/pagetypes/matching.php index b7772577a3e..a5e306c835f 100644 --- a/mod/lesson/pagetypes/matching.php +++ b/mod/lesson/pagetypes/matching.php @@ -161,18 +161,13 @@ class lesson_page_type_matching extends lesson_page { } $response = $data->response; - $empty = 0; + foreach ($response as $resp) { - if ($resp != '') { - break; - } else { - $empty ++; + if ($resp == '') { + $result->noanswer = true; + return $result; } } - if ($empty == count($response)) { - $result->noanswer = true; - return $result; - } $answers = $this->get_answers(); @@ -191,7 +186,7 @@ class lesson_page_type_matching extends lesson_page { foreach ($response as $id => $value) { $userresponse[] = $value; // Make sure the user's answer exists in question's answer - if (array_key_exists($id, $answers) && $value) { + if (array_key_exists($id, $answers)) { $answer = $answers[$id]; $result->studentanswer .= '
'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$answers[$value]->response; if ($id == $value) {