function check_file_access($question, $state, $options, $contextid, $component, $filearea, $args) { $itemid = reset($args); if ($component == 'question' && $filearea == 'answerfeedback') { // check if answer id exists $result = $options->feedback && array_key_exists($itemid, $question->options->answers); if (!$result) { return false; } // check response if (!$this->check_response($question, $state)) { return false; } return true; } else { if ($filearea == 'instruction') { // TODO: should it be display all the time like questiontext? // check if question id exists if ($itemid != $question->id) { return false; } else { return true; } } else { return parent::check_file_access($question, $state, $options, $contextid, $component, $filearea, $args); } } return true; }
function check_file_access($question, $state, $options, $contextid, $component, $filearea, $args) { $itemid = reset($args); if (empty($question->maxgrade)) { $question->maxgrade = $question->defaultgrade; } if (in_array($filearea, array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'))) { $result = $options->feedback && $itemid == $question->id; if (!$result) { return false; } if ($state->raw_grade >= $question->maxgrade / 1.01) { $feedbacktype = 'correctfeedback'; } else { if ($state->raw_grade > 0) { $feedbacktype = 'partiallycorrectfeedback'; } else { $feedbacktype = 'incorrectfeedback'; } } if ($feedbacktype != $filearea) { return false; } return true; } else { if ($component == 'question' && $filearea == 'answerfeedback') { return $options->feedback && array_key_exists($itemid, $question->options->answers); } else { return parent::check_file_access($question, $state, $options, $contextid, $component, $filearea, $args); } } }