MDL-20636 Can now display the attachments to an essay question that has attachments.
[moodle.git] / question / type / essay / question.php
index 733a78c..8e443ae 100644 (file)
@@ -55,7 +55,11 @@ class qtype_essay_question extends question_with_responses {
     }
 
     public function get_expected_data() {
     }
 
     public function get_expected_data() {
-        return array('answer' => PARAM_CLEANHTML);
+        $expecteddata = array('answer' => PARAM_CLEANHTML);
+        if ($this->attachments != 0) {
+            $expecteddata['attachments'] = question_attempt::PARAM_FILES;
+        }
+        return $expecteddata;
     }
 
     public function summarise_response(array $response) {
     }
 
     public function summarise_response(array $response) {
@@ -80,4 +84,14 @@ class qtype_essay_question extends question_with_responses {
         return question_utils::arrays_same_at_key_missing_is_blank(
                 $prevresponse, $newresponse, 'answer');
     }
         return question_utils::arrays_same_at_key_missing_is_blank(
                 $prevresponse, $newresponse, 'answer');
     }
+
+    public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
+        if ($component == 'question' && $filearea == 'response_attachments') {
+            // Response attachments visible if the question has them.
+            return $this->attachments != 0;
+
+        } else {
+            return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload);
+        }
+    }
 }
 }