Skip to content

Commit 45f69a0

Browse files
authored
Merge pull request #233 from KQMATH/issue-232
#232 Backport bugfixes from v0.8
2 parents bc66482 + c91888b commit 45f69a0

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org).
77

88
## [Unreleased]
99

10-
## [0.7.0] - planned 2023-04-28
10+
## [0.7.1] - 2024-10-10
11+
12+
- Fixed bug with uploaded images in questions not being displayed
13+
- Fixed edit/preview action links in question list
14+
15+
## [0.7.0] - 2023-04-28
1116

1217
+ Upgraded to work with Moodle 4.0
1318

classes/output/question_attempt_renderer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function render() : string {
9898
if ($attempt->is_answered()) {
9999
return $this->render_review($attempt);
100100
} else if ($attempt->is_pending()) {
101-
return $this->render_attempt($attempt, $this->attempt_display_options());
101+
return $this->render_attempt($attempt, self::attempt_display_options($this->capquiz->context()));
102102
}
103103
}
104104
return get_string('you_finished_capquiz', 'capquiz');
@@ -272,9 +272,9 @@ private function review_display_options() : \question_display_options {
272272
*
273273
* @return \question_display_options
274274
*/
275-
private function attempt_display_options() : \question_display_options {
275+
public static function attempt_display_options($context) : \question_display_options {
276276
$options = new \question_display_options();
277-
$options->context = $this->capquiz->context();
277+
$options->context = $context;
278278
$options->flags = \question_display_options::HIDDEN;
279279
$options->marks = \question_display_options::HIDDEN;
280280
$options->rightanswer = \question_display_options::HIDDEN;

classes/output/question_list_renderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ private function render_questions(capquiz_question_list $qlist) {
9696
for ($i = 0; $i < $qlist->question_count(); $i++) {
9797
$question = $questions[$i];
9898
$courseid = $question->course_id();
99-
$editurl = new \moodle_url($CFG->wwwroot . '/question/question.php', [
99+
$editurl = new \moodle_url('/question/bank/editquestion/question.php', [
100100
'courseid' => $courseid,
101101
'id' => $question->question_id()
102102
]);
103-
$previewurl = new \moodle_url($CFG->wwwroot . '/question/preview.php', [
103+
$previewurl = new \moodle_url('/question/bank/previewquestion/preview.php', [
104104
'courseid' => $courseid,
105105
'id' => $question->question_id()
106106
]);

lib.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
use mod_capquiz\capquiz;
28+
use mod_capquiz\output\question_attempt_renderer;
2829

2930
defined('MOODLE_INTERNAL') || die();
3031

@@ -238,6 +239,41 @@ function capquiz_reset_gradebook($courseid, $type = '') {
238239
}
239240
}
240241

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+
241277
/**
242278
* Checks if $feature is supported
243279
*

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727

2828
defined('MOODLE_INTERNAL') || die();
2929

30-
$plugin->version = 2023043001 ;
30+
$plugin->version = 2023043002 ;
3131
$plugin->requires = 2022041901 ; // 4.0
3232
$plugin->cron = 0;
3333
$plugin->component = 'mod_capquiz';
3434
$plugin->maturity = MATURITY_STABLE;
35-
$plugin->release = '0.7.0';
35+
$plugin->release = '0.7.1';

0 commit comments

Comments
 (0)