MDL-29970 question preview: Fill correct only if qtype supports it
[moodle.git] / question / preview.php
index e027be6..6981dd4 100644 (file)
@@ -153,12 +153,13 @@ if (data_submitted() && confirm_sesskey()) {
 
         } else if (optional_param('fill', null, PARAM_BOOL)) {
             $correctresponse = $quba->get_correct_response($slot);
-            $quba->process_action($slot, $correctresponse);
-
-            $transaction = $DB->start_delegated_transaction();
-            question_engine::save_questions_usage_by_activity($quba);
-            $transaction->allow_commit();
+            if (!is_null($correctresponse)) {
+                $quba->process_action($slot, $correctresponse);
 
+                $transaction = $DB->start_delegated_transaction();
+                question_engine::save_questions_usage_by_activity($quba);
+                $transaction->allow_commit();
+            }
             redirect($actionurl);
 
         } else if (optional_param('finish', null, PARAM_BOOL)) {
@@ -210,6 +211,8 @@ $filldisabled = '';
 if ($quba->get_question_state($slot)->is_finished()) {
     $finishdisabled = ' disabled="disabled"';
     $filldisabled = ' disabled="disabled"';
+} else if (is_null($quba->get_correct_response($slot))) {
+    $filldisabled = ' disabled="disabled"';
 }
 if (!$previewid) {
     $restartdisabled = ' disabled="disabled"';