From 20d694efa57bcca9ea2291e02945f3c64f64d3eb Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Tue, 3 Jun 2025 16:32:49 +0100 Subject: [PATCH 1/2] MDL-85200 mod_quiz: Expand behat test to cover shared bank display This extends the existing behat test for adding a question from a shared bank to confirm that the source bank is displayed with the question on the Questions page. The bank name is already passed through format_string() before being passed to the template, so additional encoding by the template is not necessary, hence the template has been changed to use triple braces. --- mod/quiz/templates/question_slot.mustache | 2 +- mod/quiz/tests/behat/editing_add_from_question_bank.feature | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mod/quiz/templates/question_slot.mustache b/mod/quiz/templates/question_slot.mustache index 9fd2beefb87..a6c4fb680b8 100644 --- a/mod/quiz/templates/question_slot.mustache +++ b/mod/quiz/templates/question_slot.mustache @@ -58,7 +58,7 @@ {{#issharedbank}}
- {{bankname}} + {{{bankname}}}
{{/issharedbank}} diff --git a/mod/quiz/tests/behat/editing_add_from_question_bank.feature b/mod/quiz/tests/behat/editing_add_from_question_bank.feature index 6afd4f58e1c..bbf4fc9ca57 100644 --- a/mod/quiz/tests/behat/editing_add_from_question_bank.feature +++ b/mod/quiz/tests/behat/editing_add_from_question_bank.feature @@ -172,6 +172,7 @@ Feature: Adding questions to a quiz from the question bank And I click on "Select" "checkbox" in the "question 03 name" "table_row" And I click on "Add selected questions to the quiz" "button" And I should see "question 03 name" + And "Qbank 1 & < > " "text" should appear after "question 03 name" "text" @javascript Scenario: Validate the sorting while adding questions from question bank From 47c54d06a6f433a5670df9f179f5fcc380eb6cc2 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Tue, 3 Jun 2025 16:34:12 +0100 Subject: [PATCH 2/2] MDL-85200 mod_quiz: Improve efficience of populate_question_sources This uses the contexts from the categories of questions in the quiz to narrow down the list of course modules we are querying to just those we will need. --- mod/quiz/classes/structure.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mod/quiz/classes/structure.php b/mod/quiz/classes/structure.php index 968ad9cda51..f261ccce796 100644 --- a/mod/quiz/classes/structure.php +++ b/mod/quiz/classes/structure.php @@ -1853,12 +1853,18 @@ class structure { private function populate_question_sources(): void { global $DB; - $sql = 'SELECT c.id AS contextid, cm.id, cm.course - FROM {question_categories} qc - JOIN {context} c ON c.id = qc.contextid - JOIN {course_modules} cm ON cm.id = c.instanceid AND c.contextlevel = ' . CONTEXT_MODULE . ' - GROUP BY c.id, cm.id, cm.course'; - $this->questionsources = $DB->get_records_sql($sql); + $contextids = array_map(fn($question) => $question->contextid, $this->questions); + [$insql, $inparams] = $DB->get_in_or_equal(array_unique($contextids)); + + $sql = " + SELECT c.id as contextid, cm.id, cm.course + FROM {context} c + JOIN {course_modules} cm ON cm.id = c.instanceid AND c.contextlevel = ? + WHERE c.id {$insql} + "; + $params = array_merge([context_module::LEVEL], $inparams); + + $this->questionsources = $DB->get_records_sql($sql, $params); } /**