|
25 | 25 | */
|
26 | 26 |
|
27 | 27 | use mod_capquiz\capquiz;
|
| 28 | +use mod_capquiz\output\question_attempt_renderer; |
28 | 29 |
|
29 | 30 | defined('MOODLE_INTERNAL') || die();
|
30 | 31 |
|
@@ -238,6 +239,41 @@ function capquiz_reset_gradebook($courseid, $type = '') {
|
238 | 239 | }
|
239 | 240 | }
|
240 | 241 |
|
| 242 | +/** |
| 243 | + * Serve question files. |
| 244 | + * |
| 245 | + * @param stdClass $course |
| 246 | + * @param stdClass $context |
| 247 | + * @param string $component |
| 248 | + * @param string $filearea |
| 249 | + * @param int $qubaid |
| 250 | + * @param int $slot |
| 251 | + * @param array $args |
| 252 | + * @param bool $forcedownload |
| 253 | + * @param array $options |
| 254 | + * @see quiz_question_pluginfile |
| 255 | + */ |
| 256 | +function capquiz_question_pluginfile(stdClass $course, stdClass $context, string $component, string $filearea, |
| 257 | + int $qubaid, int $slot, array $args, bool $forcedownload, array $options = []): void { |
| 258 | + global $DB; |
| 259 | + $user = $DB->get_record('capquiz_user', ['question_usage_id' => $qubaid]); |
| 260 | + $cm = get_coursemodule_from_instance('capquiz', $user->capquiz_id, $course->id, false, MUST_EXIST); |
| 261 | + require_login($course, false, $cm); |
| 262 | + $quba = question_engine::load_questions_usage_by_activity($qubaid); |
| 263 | + $displayoptions = question_attempt_renderer::attempt_display_options(context_module::instance($cm->id)); |
| 264 | + if (!$quba->check_file_access($slot, $displayoptions, $component, $filearea, $args, $forcedownload)) { |
| 265 | + send_file_not_found(); |
| 266 | + } |
| 267 | + $fs = get_file_storage(); |
| 268 | + $relativepath = implode('/', $args); |
| 269 | + $fullpath = "/$context->id/$component/$filearea/$relativepath"; |
| 270 | + $file = $fs->get_file_by_hash(sha1($fullpath)); |
| 271 | + if (!$file || $file->is_directory()) { |
| 272 | + send_file_not_found(); |
| 273 | + } |
| 274 | + send_stored_file($file, 0, 0, $forcedownload, $options); |
| 275 | +} |
| 276 | + |
241 | 277 | /**
|
242 | 278 | * Checks if $feature is supported
|
243 | 279 | *
|
|
0 commit comments