diff --git a/question/type/ddimageortext/lang/en/qtype_ddimageortext.php b/question/type/ddimageortext/lang/en/qtype_ddimageortext.php index 4143d01f86d..7c8c59fa7e2 100644 --- a/question/type/ddimageortext/lang/en/qtype_ddimageortext.php +++ b/question/type/ddimageortext/lang/en/qtype_ddimageortext.php @@ -70,3 +70,4 @@ $string['summarisechoiceno'] = 'Item {$a}'; $string['summariseplaceno'] = 'Drop zone {$a}'; $string['xleft'] = 'Left'; $string['ytop'] = 'Top'; +$string['deletedchoice'] = '[Deleted choice]'; diff --git a/question/type/ddimageortext/questionbase.php b/question/type/ddimageortext/questionbase.php index bbaf9bfba05..4754bf5760c 100644 --- a/question/type/ddimageortext/questionbase.php +++ b/question/type/ddimageortext/questionbase.php @@ -62,7 +62,11 @@ class qtype_ddtoimage_question_base extends qtype_gapselect_question_base { $response[$this->field($placeno)]) { $selected = $this->get_selected_choice($place->group, $response[$this->field($placeno)]); - $summarisechoice = $selected->summarise(); + if (isset($selected)) { + $summarisechoice = $selected->summarise(); + } else { + $summarisechoice = get_string('deletedchoice', 'qtype_ddimageortext'); + } $allblank = false; } else { $summarisechoice = ''; diff --git a/question/type/ddimageortext/tests/question_test.php b/question/type/ddimageortext/tests/question_test.php index 08e64b1aa77..b741bf4b7d1 100644 --- a/question/type/ddimageortext/tests/question_test.php +++ b/question/type/ddimageortext/tests/question_test.php @@ -266,4 +266,19 @@ class qtype_ddimageortext_question_test extends basic_testcase { 4 => new question_classified_response(4, '4. dog', 1) ), $dd->classify_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '2'))); } + + public function test_summarise_response_choice_deleted() { + /** @var qtype_ddtoimage_question_base $dd */ + $dd = test_question_maker::make_question('ddimageortext'); + $dd->shufflechoices = false; + $dd->start_attempt(new question_attempt_step(), 1); + // Simulation of an instructor deleting 1 choice after an attempt has been made. + unset($dd->choices[1][1]); + $delquestionstr = get_string('deletedchoice', 'qtype_ddimageortext'); + $this->assertEquals("Drop zone 1 -> {{$delquestionstr}} ". + "Drop zone 2 -> {{$delquestionstr}} ". + 'Drop zone 3 -> {3. lazy} '. + 'Drop zone 4 -> {3. lazy}', + $dd->summarise_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1'))); + } } diff --git a/question/type/gapselect/questionbase.php b/question/type/gapselect/questionbase.php index 76a3882a87b..a64e67c2191 100644 --- a/question/type/gapselect/questionbase.php +++ b/question/type/gapselect/questionbase.php @@ -127,7 +127,7 @@ abstract class qtype_gapselect_question_base extends question_graded_automatical protected function get_selected_choice($group, $shuffledchoicenumber) { $choiceno = $this->choiceorder[$group][$shuffledchoicenumber]; - return $this->choices[$group][$choiceno]; + return isset($this->choices[$group][$choiceno]) ? $this->choices[$group][$choiceno] : null; } public function summarise_response(array $response) {