/** * Called via pluginfile.php -> question_pluginfile to serve files belonging to * a question in a question_attempt when that attempt is a quiz attempt. * * @param object $course course settings object * @param object $context context object * @param string $component the name of the component we are serving files for. * @param string $filearea the name of the file area. * @param array $args the remaining bits of the file path. * @param bool $forcedownload whether the user must be forced to download the file. * @return bool false if file not found, does not return if found - justsend the file */ function quiz_question_pluginfile($course, $context, $component, $filearea, $uniqueid, $questionid, $args, $forcedownload) { global $USER, $CFG; require_once($CFG->dirroot . '/mod/quiz/locallib.php'); $attemptobj = quiz_attempt::create_from_unique_id($uniqueid); require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm()); $questionids = array($questionid); $attemptobj->load_questions($questionids); $attemptobj->load_question_states($questionids); if ($attemptobj->is_own_attempt() && !$attemptobj->is_finished()) { // In the middle of an attempt. if (!$attemptobj->is_preview_user()) { $attemptobj->require_capability('mod/quiz:attempt'); } $isreviewing = false; } else { // Reviewing an attempt. $attemptobj->check_review_capability(); $isreviewing = true; } if (!$attemptobj->check_file_access($questionid, $isreviewing, $context->id, $component, $filearea, $args, $forcedownload)) { send_file_not_found(); } $fs = get_file_storage(); $relativepath = implode('/', $args); $fullpath = "/$context->id/$component/$filearea/$relativepath"; if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { send_file_not_found(); } send_stored_file($file, 0, 0, $forcedownload); }