From 86ff8ccd221fa4ab0147b2618c7f75259df5b2f1 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 29 Mar 2017 11:01:02 +0200 Subject: [PATCH] MDL-57757 mod_lesson: Handle empty answers This is and edge case created by a bug in the numeric question type. --- mod/lesson/classes/external.php | 6 ++++-- mod/lesson/report.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mod/lesson/classes/external.php b/mod/lesson/classes/external.php index 55f428c7f7b..569a02b8754 100644 --- a/mod/lesson/classes/external.php +++ b/mod/lesson/classes/external.php @@ -1860,8 +1860,10 @@ class mod_lesson_external extends external_api { 'response' => new external_value(PARAM_RAW, 'The response text.'), 'responseformat' => new external_format_value('response.'), 'answers' => new external_multiple_structure( - new external_multiple_structure(new external_value(PARAM_RAW, 'Possible answers and info.')) - ) + new external_multiple_structure(new external_value(PARAM_RAW, 'Possible answers and info.')), + 'User answers', + VALUE_OPTIONAL + ), ), 'Answer data (empty in content pages created in Moodle 1.x).', VALUE_OPTIONAL ) ) diff --git a/mod/lesson/report.php b/mod/lesson/report.php index bb21b49bcbc..548411b308c 100644 --- a/mod/lesson/report.php +++ b/mod/lesson/report.php @@ -328,7 +328,7 @@ if ($action === 'delete') { $table->data[] = array($fontstart.get_string("question", "lesson").":
".$fontend.$fontstart2.$page->contents.$fontend2, " "); $table->data[] = array($fontstart.get_string("answer", "lesson").":".$fontend, ' '); // apply the font to each answer - if (!empty($page->answerdata)) { + if (!empty($page->answerdata->answers)) { foreach ($page->answerdata->answers as $answer){ $modified = array(); foreach ($answer as $single) {