From c91888b448068a2f5e8d1b7ee758928f10640b4c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 10 Oct 2024 22:44:57 +0200 Subject: [PATCH] #232 Backport bugfixes from v0.8 --- CHANGELOG.md | 7 +++- classes/output/question_attempt_renderer.php | 6 ++-- classes/output/question_list_renderer.php | 4 +-- lib.php | 36 ++++++++++++++++++++ version.php | 4 +-- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1b458c..5e26588 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org). ## [Unreleased] -## [0.7.0] - planned 2023-04-28 +## [0.7.1] - 2024-10-10 + +- Fixed bug with uploaded images in questions not being displayed +- Fixed edit/preview action links in question list + +## [0.7.0] - 2023-04-28 + Upgraded to work with Moodle 4.0 diff --git a/classes/output/question_attempt_renderer.php b/classes/output/question_attempt_renderer.php index 63e9a90..b806c9d 100755 --- a/classes/output/question_attempt_renderer.php +++ b/classes/output/question_attempt_renderer.php @@ -98,7 +98,7 @@ public function render() : string { if ($attempt->is_answered()) { return $this->render_review($attempt); } else if ($attempt->is_pending()) { - return $this->render_attempt($attempt, $this->attempt_display_options()); + return $this->render_attempt($attempt, self::attempt_display_options($this->capquiz->context())); } } return get_string('you_finished_capquiz', 'capquiz'); @@ -272,9 +272,9 @@ private function review_display_options() : \question_display_options { * * @return \question_display_options */ - private function attempt_display_options() : \question_display_options { + public static function attempt_display_options($context) : \question_display_options { $options = new \question_display_options(); - $options->context = $this->capquiz->context(); + $options->context = $context; $options->flags = \question_display_options::HIDDEN; $options->marks = \question_display_options::HIDDEN; $options->rightanswer = \question_display_options::HIDDEN; diff --git a/classes/output/question_list_renderer.php b/classes/output/question_list_renderer.php index 4508ac4..5d33368 100644 --- a/classes/output/question_list_renderer.php +++ b/classes/output/question_list_renderer.php @@ -96,11 +96,11 @@ private function render_questions(capquiz_question_list $qlist) { for ($i = 0; $i < $qlist->question_count(); $i++) { $question = $questions[$i]; $courseid = $question->course_id(); - $editurl = new \moodle_url($CFG->wwwroot . '/question/question.php', [ + $editurl = new \moodle_url('/question/bank/editquestion/question.php', [ 'courseid' => $courseid, 'id' => $question->question_id() ]); - $previewurl = new \moodle_url($CFG->wwwroot . '/question/preview.php', [ + $previewurl = new \moodle_url('/question/bank/previewquestion/preview.php', [ 'courseid' => $courseid, 'id' => $question->question_id() ]); diff --git a/lib.php b/lib.php index 1f35ca1..1183e06 100755 --- a/lib.php +++ b/lib.php @@ -25,6 +25,7 @@ */ use mod_capquiz\capquiz; +use mod_capquiz\output\question_attempt_renderer; defined('MOODLE_INTERNAL') || die(); @@ -238,6 +239,41 @@ function capquiz_reset_gradebook($courseid, $type = '') { } } +/** + * Serve question files. + * + * @param stdClass $course + * @param stdClass $context + * @param string $component + * @param string $filearea + * @param int $qubaid + * @param int $slot + * @param array $args + * @param bool $forcedownload + * @param array $options + * @see quiz_question_pluginfile + */ +function capquiz_question_pluginfile(stdClass $course, stdClass $context, string $component, string $filearea, + int $qubaid, int $slot, array $args, bool $forcedownload, array $options = []): void { + global $DB; + $user = $DB->get_record('capquiz_user', ['question_usage_id' => $qubaid]); + $cm = get_coursemodule_from_instance('capquiz', $user->capquiz_id, $course->id, false, MUST_EXIST); + require_login($course, false, $cm); + $quba = question_engine::load_questions_usage_by_activity($qubaid); + $displayoptions = question_attempt_renderer::attempt_display_options(context_module::instance($cm->id)); + if (!$quba->check_file_access($slot, $displayoptions, $component, $filearea, $args, $forcedownload)) { + send_file_not_found(); + } + $fs = get_file_storage(); + $relativepath = implode('/', $args); + $fullpath = "/$context->id/$component/$filearea/$relativepath"; + $file = $fs->get_file_by_hash(sha1($fullpath)); + if (!$file || $file->is_directory()) { + send_file_not_found(); + } + send_stored_file($file, 0, 0, $forcedownload, $options); +} + /** * Checks if $feature is supported * diff --git a/version.php b/version.php index b928a86..eaaec7d 100755 --- a/version.php +++ b/version.php @@ -27,9 +27,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023043001 ; +$plugin->version = 2023043002 ; $plugin->requires = 2022041901 ; // 4.0 $plugin->cron = 0; $plugin->component = 'mod_capquiz'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '0.7.0'; +$plugin->release = '0.7.1';