Skip to content

Commit 604bf5c

Browse files
committed
Fix upload when several file upload questions are used.
- Adjust siganture of methods to their parent - Limit the files to upload to one for each question - Use questionaire id for file draft area instead of question id in the questionaire.
1 parent c6bbfe2 commit 604bf5c

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

classes/file_storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace mod_questionnaire;
1818

1919
/**
20-
* Defines the file stoeage class for questionnaire.
20+
* Defines the file storage class for questionnaire.
2121
* @package mod_questionnaire
2222
* @copyright 2020 onwards Mike Churchward ([email protected])
2323
* @author Mike Churchward

classes/question/file.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ protected function responseclass() {
7070
/**
7171
* Survey display output.
7272
*
73-
* @param response $response
73+
* @param \stdClass $formdata
7474
* @param object $descendantsdata
7575
* @param bool $blankquestionnaire
76-
* @return object|string
76+
* @return string
7777
*/
78-
protected function question_survey_display($response, $descendantsdata, $blankquestionnaire = false) {
78+
protected function question_survey_display($formdata, $descendantsdata, $blankquestionnaire = false) {
7979
global $CFG, $PAGE;
8080
require_once($CFG->libdir . '/filelib.php');
8181
$elname = 'q' . $this->id;
@@ -114,27 +114,29 @@ private function get_file_manager_option() {
114114
return [
115115
'mainfile' => '',
116116
'subdirs' => false,
117-
'accepted_types' => array('image', '.pdf')
117+
'accepted_types' => array('image', '.pdf'),
118+
'maxfiles' => 1,
118119
];
119120
}
120121

121122
/**
122123
* Response display output.
123124
*
124-
* @param response $response
125-
* @return object|string
125+
* @param \stdClass $data
126+
* @return string
126127
*/
127-
protected function response_survey_display($response) {
128+
protected function response_survey_display($data) {
128129
global $PAGE, $CFG;
129130
require_once($CFG->libdir . '/filelib.php');
130131
require_once($CFG->libdir . '/resourcelib.php');
131-
if (isset($response->answers[$this->id])) {
132-
$answer = reset($response->answers[$this->id]);
132+
if (isset($data->answers[$this->id])) {
133+
$answer = reset($data->answers[$this->id]);
133134
} else {
134135
return '';
135136
}
136137
$fs = get_file_storage();
137138
$file = $fs->get_file_by_id($answer->value);
139+
$code = '';
138140

139141
if ($file) {
140142
// There is a file.
@@ -150,8 +152,6 @@ protected function response_survey_display($response) {
150152
$mimetype = $file->get_mimetype();
151153
$title = '';
152154

153-
$extension = resourcelib_get_extension($file->get_filename());
154-
155155
$mediamanager = core_media_manager::instance($PAGE);
156156
$embedoptions = array(
157157
core_media_manager::OPTION_TRUSTED => true,
@@ -177,11 +177,7 @@ protected function response_survey_display($response) {
177177
$code = resourcelib_embed_general($moodleurl, $title, get_string('view'), $mimetype);
178178
}
179179
}
180-
$output = '';
181-
$output .= '<div class="response text">';
182-
$output .= $code;
183-
$output .= '</div>';
184-
return $output;
180+
return '<div class="response text">' . $code . '</div>';
185181
}
186182

187183
/**

classes/responsetype/file.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public static function answers_from_webform($responsedata, $question) {
4343
$record->responseid = $responsedata->rid;
4444
$record->questionid = $question->id;
4545

46-
file_save_draft_area_files($val, $question->context->id, 'mod_questionnaire', 'file', $responsedata->rid);
46+
file_save_draft_area_files($val, $question->context->id, 'mod_questionnaire', 'file', $question->id);
4747
$fs = get_file_storage();
48-
$files = $fs->get_area_files($question->context->id, 'mod_questionnaire', 'file', $responsedata->rid,
48+
$files = $fs->get_area_files($question->context->id, 'mod_questionnaire', 'file', $question->id,
4949
"itemid, filepath, filename",
5050
false);
5151
$file = reset($files);

classes/responsetype/response/response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public static function create_from_data($responsedata) {
9999
/**
100100
* Provide a response object from web form data to the question.
101101
*
102-
* @param \stdClass $responsedata All of the responsedata as an object.
102+
* @param \stdClass $responsedata All the responsedata as an object.
103103
* @param array $questions
104-
* @return bool|response A response object.
104+
* @return response A response object.
105105
*/
106106
public static function response_from_webform($responsedata, $questions) {
107107
global $USER;

questionnaire.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ public function add_survey($sid = 0, $survey = null) {
122122

123123
/**
124124
* Adding questions to the object.
125-
* @param bool $sid
125+
* @param int $sid
126126
*/
127-
public function add_questions($sid = false) {
127+
public function add_questions($sid = 0) {
128128
global $DB;
129129

130-
if ($sid === false) {
130+
if ($sid === 0) {
131131
$sid = $this->sid;
132132
}
133133

0 commit comments

Comments
 (0)