From 42cb48db5c6cffbc23ae4f7682c2182fae5df411 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Wed, 14 Jan 2026 11:56:41 +0000 Subject: [PATCH] MDL-85653 qbank_editquestion: Display static status when not editable --- .../classes/editquestion_helper.php | 6 ++++- .../classes/question_status_column.php | 4 ++- .../tests/behat/question_status.feature | 25 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/public/question/bank/editquestion/classes/editquestion_helper.php b/public/question/bank/editquestion/classes/editquestion_helper.php index 6eb1b25e901..c88c27dd6b9 100644 --- a/public/question/bank/editquestion/classes/editquestion_helper.php +++ b/public/question/bank/editquestion/classes/editquestion_helper.php @@ -92,12 +92,16 @@ class editquestion_helper { /** * Get the array of status of the questions. * + * @param bool $includehidden Include QUESTION_STATUS_HIDDEN in the returned list? * @return array */ - public static function get_question_status_list(): array { + public static function get_question_status_list(bool $includehidden = false): array { $statuslist = []; $statuslist[question_version_status::QUESTION_STATUS_READY] = get_string('questionstatusready', 'qbank_editquestion'); $statuslist[question_version_status::QUESTION_STATUS_DRAFT] = get_string('questionstatusdraft', 'qbank_editquestion'); + if ($includehidden) { + $statuslist[question_version_status::QUESTION_STATUS_HIDDEN] = get_string('questionstatushidden', 'qbank_editquestion'); + } return $statuslist; } diff --git a/public/question/bank/editquestion/classes/question_status_column.php b/public/question/bank/editquestion/classes/question_status_column.php index 7b6b6b822c6..33793f5e2df 100644 --- a/public/question/bank/editquestion/classes/question_status_column.php +++ b/public/question/bank/editquestion/classes/question_status_column.php @@ -39,7 +39,6 @@ class question_status_column extends column_base { protected function display_content($question, $rowclasses): void { global $PAGE; - $attributes = []; if (question_has_capability_on($question, 'edit') && $question->status !== question_version_status::QUESTION_STATUS_HIDDEN) { $options = []; @@ -54,6 +53,9 @@ class question_status_column extends column_base { } echo $PAGE->get_renderer('qbank_editquestion')->render_status_dropdown($options); $PAGE->requires->js_call_amd('qbank_editquestion/question_status', 'init', [$question->id]); + } else { + $statuslist = editquestion_helper::get_question_status_list(true); + echo $statuslist[$question->status]; } } diff --git a/public/question/bank/editquestion/tests/behat/question_status.feature b/public/question/bank/editquestion/tests/behat/question_status.feature index a040c68d4d5..307f729191b 100644 --- a/public/question/bank/editquestion/tests/behat/question_status.feature +++ b/public/question/bank/editquestion/tests/behat/question_status.feature @@ -33,3 +33,28 @@ Feature: Use the qbank base view to test the status change using And I reload the page And the field "question_status_dropdown" in the "First question" "table_row" matches value "Ready" And the field "question_status_dropdown" in the "Second question" "table_row" matches value "Draft" + + @javascript + Scenario: Non-editing users see a static output of the status + Given the following "users" exist: + | username | firstname | lastname | + | teacher1 | Teacher | 1 | + And the following "permission overrides" exist: + | capability | permission | role | contextlevel | reference | + | moodle/question:editall | Prevent | editingteacher | System | | + And the following "course enrolments" exist: + | course | user | role | + | C1 | teacher1 | editingteacher | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | status | + | Test questions | truefalse | Third question | Answer the first question | draft | + | Test questions | truefalse | Fourth question | Answer the first question | hidden | + When I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1" + And I apply question bank filter "Category" with value "Test questions" + And I apply question bank filter "Show hidden questions" with value "Yes" + Then I should see "Test questions" + And "question_status_dropdown" "field" should not exist + And I should see "Ready" in the "First question" "table_row" + And I should see "Ready" in the "Second question" "table_row" + And I should see "Draft" in the "Third question" "table_row" + And I should see "Hidden" in the "Fourth question" "table_row"