diff --git a/mod/quiz/classes/question/bank/custom_view.php b/mod/quiz/classes/question/bank/custom_view.php
index e4d52694e6b..8eef0ef1358 100644
--- a/mod/quiz/classes/question/bank/custom_view.php
+++ b/mod/quiz/classes/question/bank/custom_view.php
@@ -207,7 +207,7 @@ class custom_view extends \core_question\bank\view {
}
protected function print_category_info($category) {
- $formatoptions = new stdClass();
+ $formatoptions = new \stdClass();
$formatoptions->noclean = true;
$strcategory = get_string('category', 'quiz');
echo '
' .
diff --git a/mod/quiz/classes/question/bank/question_name_text_column.php b/mod/quiz/classes/question/bank/question_name_text_column.php
index fa15f54097d..ecde32767f0 100644
--- a/mod/quiz/classes/question/bank/question_name_text_column.php
+++ b/mod/quiz/classes/question/bank/question_name_text_column.php
@@ -44,7 +44,7 @@ class question_name_text_column extends \core_question\bank\question_name_column
if ($labelfor) {
echo '';
}
@@ -55,6 +55,12 @@ class question_name_text_column extends \core_question\bank\question_name_column
$fields = parent::get_required_fields();
$fields[] = 'q.questiontext';
$fields[] = 'q.questiontextformat';
+ $fields[] = 'q.idnumber';
return $fields;
}
+
+ public function load_additional_data(array $questions) {
+ parent::load_additional_data($questions);
+ parent::load_question_tags($questions);
+ }
}
diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php
index 8db703b5ce7..ad16a5ad8a6 100644
--- a/mod/quiz/locallib.php
+++ b/mod/quiz/locallib.php
@@ -2048,17 +2048,43 @@ class qubaids_for_quiz_user extends qubaid_join {
* @param bool $showicon If true, show the question's icon with the question. False by default.
* @param bool $showquestiontext If true (default), show question text after question name.
* If false, show only question name.
- * @return string
+ * @param bool $showidnumber If true, show the question's idnumber, if any. False by default.
+ * @param core_tag_tag[]|bool $showtags if array passed, show those tags. Else, if true, get and show tags,
+ * else, don't show tags (which is the default).
+ * @return string HTML fragment.
*/
-function quiz_question_tostring($question, $showicon = false, $showquestiontext = true) {
+function quiz_question_tostring($question, $showicon = false, $showquestiontext = true,
+ $showidnumber = false, $showtags = false) {
+ global $OUTPUT;
$result = '';
+ // Question name.
$name = shorten_text(format_string($question->name), 200);
if ($showicon) {
$name .= print_question_icon($question) . ' ' . $name;
}
$result .= html_writer::span($name, 'questionname');
+ // Question idnumber.
+ if ($showidnumber && $question->idnumber !== null && $question->idnumber !== '') {
+ $result .= ' ' . html_writer::span(
+ html_writer::span(get_string('idnumber', 'question'), 'accesshide') .
+ ' ' . $question->idnumber, 'badge badge-primary');
+ }
+
+ // Question tags.
+ if (is_array($showtags)) {
+ $tags = $showtags;
+ } else if ($showtags) {
+ $tags = core_tag_tag::get_item_tags('core_question', 'question', $question->id);
+ } else {
+ $tags = [];
+ }
+ if ($tags) {
+ $result .= $OUTPUT->tag_list($tags, null, 'd-inline', 0, null, true);
+ }
+
+ // Question text.
if ($showquestiontext) {
$questiontext = question_utils::to_plain_text($question->questiontext,
$question->questiontextformat, array('noclean' => true, 'para' => false));
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 56e983d5f4c..2e8708e82c5 100644
--- a/mod/quiz/tests/behat/editing_add_from_question_bank.feature
+++ b/mod/quiz/tests/behat/editing_add_from_question_bank.feature
@@ -21,9 +21,9 @@ Feature: Adding questions to a quiz from the question bank
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
- | questioncategory | qtype | name | user | questiontext |
- | Test questions | essay | question 01 name | admin | Question 01 text |
- | Test questions | essay | question 02 name | teacher1 | Question 02 text |
+ | questioncategory | qtype | name | user | questiontext | idnumber |
+ | Test questions | essay | question 01 name | admin | Question 01 text | |
+ | Test questions | essay | question 02 name | teacher1 | Question 02 text | qidnum |
Scenario: The questions can be filtered by tag
Given I log in as "teacher1"
@@ -42,9 +42,12 @@ Feature: Adding questions to a quiz from the question bank
And I navigate to "Edit quiz" in current page administration
And I open the "last" add to quiz menu
And I follow "from question bank"
+ Then I should see "foo" in the "question 01 name" "table_row"
+ And I should see "bar" in the "question 02 name" "table_row"
+ And I should see "qidnum" in the "question 02 name" "table_row"
And I set the field "Filter by tags..." to "foo"
And I press key "13" in the field "Filter by tags..."
- Then I should see "question 01 name" in the "categoryquestions" "table"
+ And I should see "question 01 name" in the "categoryquestions" "table"
And I should not see "question 02 name" in the "categoryquestions" "table"
Scenario: The question modal can be paginated