@@ -70,20 +70,25 @@ protected function responseclass() {
70
70
/**
71
71
* Survey display output.
72
72
*
73
- * @param \stdClass $formdata
73
+ * @param response $response
74
74
* @param object $descendantsdata
75
75
* @param bool $blankquestionnaire
76
76
* @return string
77
77
*/
78
- protected function question_survey_display ($ formdata , $ descendantsdata , $ blankquestionnaire = false ) {
78
+ protected function question_survey_display ($ response , $ descendantsdata , $ blankquestionnaire = false ) {
79
79
global $ CFG , $ PAGE ;
80
80
require_once ($ CFG ->libdir . '/filelib.php ' );
81
+
81
82
$ elname = 'q ' . $ this ->id ;
82
- $ draftitemid = file_get_submitted_draft_itemid ($ elname );
83
- $ component = 'mod_questionnaire ' ;
83
+ // Make sure there is a response, fetch the draft id from the original request.
84
+ if (isset ($ response ->answers [$ this ->id ]) && !empty ($ response ->answers [$ this ->id ]) && isset ($ _REQUEST [$ elname . 'draft ' ])) {
85
+ $ draftitemid = (int )$ _REQUEST [$ elname . 'draft ' ];
86
+ } else {
87
+ $ draftitemid = file_get_submitted_draft_itemid ($ elname );
88
+ }
84
89
$ options = self ::get_file_manager_option ();
85
90
if ($ draftitemid > 0 ) {
86
- file_prepare_draft_area ($ draftitemid , $ this ->context ->id , $ component , 'file ' , $ this ->id , $ options );
91
+ file_prepare_draft_area ($ draftitemid , $ this ->context ->id , ' mod_questionnaire ' , 'file ' , $ this ->id , $ options );
87
92
} else {
88
93
$ draftitemid = file_get_unused_draft_itemid ();
89
94
}
@@ -101,14 +106,40 @@ protected function question_survey_display($formdata, $descendantsdata, $blankqu
101
106
);
102
107
$ fm = new form_filemanager ((object ) $ fmoptions );
103
108
$ output = $ PAGE ->get_renderer ('core ' , 'files ' );
104
- $ html = $ output ->render ($ fm );
105
109
106
- $ html .= '<input value=" ' . $ draftitemid . '" name=" ' . $ elname . '" type="hidden" /> ' ;
107
- $ html .= '<input value="" id=" ' . $ this ->id . '" type="hidden" /> ' ;
110
+ $ html = '<div class="form-filemanager" data-fieldtype="filemanager"> ' .
111
+ $ output ->render ($ fm ) .
112
+ '<input type="hidden" name=" ' . $ elname . '" value=" ' . $ draftitemid . '" /> ' .
113
+ '<input type="hidden" name=" ' . $ elname . 'draft" value=" ' . $ draftitemid . '" /> ' .
114
+ '</div> ' ;
108
115
109
116
return $ html ;
110
117
}
111
118
119
+ /**
120
+ * Check question's form data for complete response.
121
+ * @param \stdClass $responsedata The data entered into the response.
122
+ * @return bool
123
+ */
124
+ public function response_complete ($ responsedata ) {
125
+ $ answered = false ;
126
+ // If $responsedata is a response object, look through the answers.
127
+ if (is_a ($ responsedata , 'mod_questionnaire\responsetype\response\response ' ) &&
128
+ isset ($ responsedata ->answers [$ this ->id ]) && !empty ($ responsedata ->answers [$ this ->id ])
129
+ ) {
130
+ $ answer = reset ($ responsedata ->answers [$ this ->id ]);
131
+ $ answered = ((int )$ answer ->value > 0 );
132
+ // If $responsedata is webform data, check that it is not empty.
133
+ } else if (isset ($ responsedata ->{'q ' .$ this ->id })) {
134
+ $ draftitemid = (int )$ responsedata ->{'q ' . $ this ->id };
135
+ if ($ draftitemid > 0 ) {
136
+ $ info = file_get_draft_area_info ($ draftitemid );
137
+ $ answered = $ info ['filecount ' ] > 0 ;
138
+ }
139
+ }
140
+ return !($ this ->required () && ($ this ->deleted == 'n ' ) && !$ answered );
141
+ }
142
+
112
143
/**
113
144
* Get file manager options
114
145
*
0 commit comments