From b0e9cdd45bc9a32504dd27c623586976b0084643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joseph=20R=C3=A9zeau?= Date: Fri, 3 May 2013 11:00:43 +0200 Subject: [PATCH] MDL-39488 Lesson Module: Fix for "Match question throws PHP error if one or more options have not been selected " MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Joseph Rézeau --- mod/lesson/pagetypes/matching.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mod/lesson/pagetypes/matching.php b/mod/lesson/pagetypes/matching.php index b110d1de1e5..81f26174ef8 100644 --- a/mod/lesson/pagetypes/matching.php +++ b/mod/lesson/pagetypes/matching.php @@ -161,7 +161,15 @@ class lesson_page_type_matching extends lesson_page { } $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; return $result; } @@ -177,13 +185,13 @@ class lesson_page_type_matching extends lesson_page { } unset($answers[$key]); } - // get he users exact responses for record keeping + // get the user's exact responses for record keeping $hits = 0; $userresponse = array(); foreach ($response as $id => $value) { $userresponse[] = $value; - // Make sure the user's answer is exist in question's answer - if (array_key_exists($id, $answers)) { + // Make sure the user's answer exists in question's answer + if (array_key_exists($id, $answers) && $value) { $answer = $answers[$id]; $result->studentanswer .= '
'.format_text($answer->answer, $answer->answerformat, $formattextdefoptions).' = '.$answers[$value]->response; if ($id == $value) {