From 13ee9a2639e651685c36a2bb048db1ec6052e7ee Mon Sep 17 00:00:00 2001 From: James Pratt Date: Fri, 18 Apr 2014 19:40:50 +0700 Subject: [PATCH] MDL-47494 ddimageortext: MDL-45111 quiz responses report : fatal error when counting responses not all possible responses where returned by question type method. --- question/type/ddimageortext/questionbase.php | 8 ++++++-- question/type/ddimageortext/questiontypebase.php | 13 +++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/question/type/ddimageortext/questionbase.php b/question/type/ddimageortext/questionbase.php index 6c75098985c..38b1a96eadd 100644 --- a/question/type/ddimageortext/questionbase.php +++ b/question/type/ddimageortext/questionbase.php @@ -122,8 +122,12 @@ class qtype_ddtoimage_question_base extends qtype_gapselect_question_base { $choice = $this->choices[$group][$choiceno]; $correct = $this->get_right_choice_for($placeno) == $response[$fieldname]; - $parts[$placeno] = new question_classified_response( - $choiceno, $choice->summarise(), $correct?1:0); + if ($correct) { + $grade = 1; + } else { + $grade = 0; + } + $parts[$placeno] = new question_classified_response($choiceno, $choice->summarise(), $grade); } return $parts; } diff --git a/question/type/ddimageortext/questiontypebase.php b/question/type/ddimageortext/questiontypebase.php index 7acfca73cd0..2512852da0d 100644 --- a/question/type/ddimageortext/questiontypebase.php +++ b/question/type/ddimageortext/questiontypebase.php @@ -60,7 +60,7 @@ class qtype_ddtoimage_base extends question_type { $this->initialise_combined_feedback($question, $questiondata, true); $question->choices = array(); - $choiceindexmap= array(); + $choiceindexmap = array(); // Store the choices in arrays by group. foreach ($questiondata->options->drags as $dragdata) { @@ -165,18 +165,11 @@ class qtype_ddtoimage_base extends question_type { $parts = array(); foreach ($question->places as $placeno => $place) { - $group = $place->group; $choices = array(); - foreach ($question->choices[$group] as $i => $choice) { - $summarisechoice = $choice->summarise(); - + foreach ($question->choices[$place->group] as $i => $choice) { $correct = $question->rightchoices[$placeno] == $i; - if ($correct) { - $choices[$choice->no] = new question_possible_response( - $summarisechoice, - $correct?1:0); - } + $choices[$choice->no] = new question_possible_response($choice->summarise(), $correct ? 1 : 0); } $choices[null] = question_possible_response::no_response();