MDL-57757 mod_lesson: Handle empty answers

This is and edge case created by a bug in the numeric question type.
This commit is contained in:
Juan Leyva 2017-03-29 11:01:02 +02:00
parent 79d5e88215
commit 86ff8ccd22
2 changed files with 5 additions and 3 deletions

View file

@ -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
)
)

View file

@ -328,7 +328,7 @@ if ($action === 'delete') {
$table->data[] = array($fontstart.get_string("question", "lesson").": <br />".$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) {