MDL-20636 Conversion of the essay question type.
[moodle.git] / question / type / truefalse / question.php
index 7e1a9b8..8a6a982 100644 (file)
@@ -35,6 +35,8 @@ class qtype_truefalse_question extends question_graded_automatically {
     public $rightanswer;
     public $truefeedback;
     public $falsefeedback;
+    public $trueanswerid;
+    public $falseanswerid;
 
     public function get_expected_data() {
         return array('answer' => PARAM_INTEGER);
@@ -94,4 +96,17 @@ class qtype_truefalse_question extends question_graded_automatically {
         }
         return array($fraction, question_state::graded_state_for_fraction($fraction));
     }
+
+    public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
+        if ($component == 'question' && $filearea == 'answerfeedback') {
+            $answerid = reset($args); // itemid is answer id.
+            $response = $qa->get_last_qt_var('answer', '');
+            return $options->feedback && (
+                    ($answerid == $this->trueanswerid && $response) ||
+                    ($answerid == $this->falseanswerid && $response !== ''));
+
+        } else {
+            return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload);
+        }
+    }
 }