Merge branch 'MDL-52791' of git://github.com/timhunt/moodle
authorDan Poltawski <dan@moodle.com>
Mon, 25 Jan 2016 14:26:59 +0000 (14:26 +0000)
committerDavid Monllao <davidm@moodle.com>
Fri, 29 Jan 2016 02:15:19 +0000 (10:15 +0800)
mod/quiz/classes/structure.php

index a02fabe..36c3499 100644 (file)
@@ -181,7 +181,7 @@ class structure {
             return false;
         }
 
-        if ($this->get_question_type_for_slot($slotnumber) == 'random') {
+        if (in_array($this->get_question_type_for_slot($slotnumber), array('random', 'missingtype'))) {
             return \question_engine::can_questions_finish_during_the_attempt(
                     $this->quizobj->get_quiz()->preferredbehaviour);
         }
@@ -190,14 +190,19 @@ class structure {
             return $this->slotsinorder[$slotnumber]->canfinish;
         }
 
-        $quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $this->quizobj->get_context());
-        $tempslot = $quba->add_question(\question_bank::load_question(
-                $this->slotsinorder[$slotnumber]->questionid));
-        $quba->set_preferred_behaviour($this->quizobj->get_quiz()->preferredbehaviour);
-        $quba->start_all_questions();
+        try {
+            $quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $this->quizobj->get_context());
+            $tempslot = $quba->add_question(\question_bank::load_question(
+                    $this->slotsinorder[$slotnumber]->questionid));
+            $quba->set_preferred_behaviour($this->quizobj->get_quiz()->preferredbehaviour);
+            $quba->start_all_questions();
 
-        $this->slotsinorder[$slotnumber]->canfinish = $quba->can_question_finish_during_attempt($tempslot);
-        return $this->slotsinorder[$slotnumber]->canfinish;
+            $this->slotsinorder[$slotnumber]->canfinish = $quba->can_question_finish_during_attempt($tempslot);
+            return $this->slotsinorder[$slotnumber]->canfinish;
+        } catch (\Exception $e) {
+            // If the question fails to start, this should not block editing.
+            return false;
+        }
     }
 
     /**