From f10a1dba9ff63e9908b43180828ace590f69246e Mon Sep 17 00:00:00 2001 From: Khoa Nguyen Date: Wed, 11 Dec 2024 15:45:55 +0700 Subject: [PATCH] MDL-83832 core_question: Links to question history may show blank page --- .../bank/history/classes/history_action.php | 22 ++++++++++++++++++- .../behat/question_history_action.feature | 20 +++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/question/bank/history/classes/history_action.php b/question/bank/history/classes/history_action.php index 7157cf806d6..499cf6e478c 100644 --- a/question/bank/history/classes/history_action.php +++ b/question/bank/history/classes/history_action.php @@ -16,7 +16,9 @@ namespace qbank_history; +use core_question\local\bank\condition; use core_question\local\bank\question_action_base; +use core_question\local\bank\filter_condition_manager; /** * Question bank column for the history action icon. @@ -49,11 +51,29 @@ class history_action extends question_action_base { } if (question_has_capability_on($question, 'use')) { + $currentfilter = $this->qbank->base_url()->param('filter'); + if ($currentfilter) { + $currentfilter = filter_condition_manager::update_filter_param_to_category( + $currentfilter, $question->categoryid); + } else { + $currentfilter = json_encode([ + 'category' => [ + 'jointype' => condition::JOINTYPE_DEFAULT, + 'values' => [$question->categoryid], + 'filteroptions' => ['includesubcategories' => false], + ], + 'hidden' => [ + 'jointype' => condition::JOINTYPE_DEFAULT, + 'values' => [0], + ], + ]); + } + $url = helper::question_history_url( $question->questionbankentryid, $this->qbank->returnurl, $this->qbank->course->id, - $this->qbank->base_url()->param('filter'), + $currentfilter, ); return [$url, 't/log', $this->strpreview]; } diff --git a/question/bank/history/tests/behat/question_history_action.feature b/question/bank/history/tests/behat/question_history_action.feature index ac1ca5877f0..f9dd7b742b3 100644 --- a/question/bank/history/tests/behat/question_history_action.feature +++ b/question/bank/history/tests/behat/question_history_action.feature @@ -55,6 +55,26 @@ Feature: Use the qbank plugin manager page for question history And I should see "Second question" And "Second question" "table_row" should exist + Scenario: Viewing history for a Question in a Subcategory + Given the following "question categories" exist: + | contextlevel | reference | questioncategory | name | + | Course | C1 | Test questions | Subcategory 1 | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Subcategory 1 | truefalse | Question (v1) | Question version 1 | + When I am on the "Course 1" "core_question > course question categories" page logged in as "admin" + And I should see "Subcategory 1" + And I click on "Subcategory 1" "link" + Then I should see "Question (v1)" + And I choose "Edit question" action for "Question (v1)" in the question bank + And I set the following fields to these values: + | Question name | Question (v2) | + | Question text | Question version 2 | + And I press "id_submitbutton" + And I choose "History" action for "Question (v2)" in the question bank + And "Question (v1)" "table_row" should exist + And "Question (v2)" "table_row" should exist + @javascript Scenario: Delete question from the history using Edit question menu Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "admin"