Commit c2200bd5 authored by Tim Hunt's avatar Tim Hunt
Browse files

MDL-66553 quiz/questions: show idnumber and tags when adding from qbank

parent 61cc1e64
......@@ -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 '<div class="categoryinfo"><div class="categorynamefieldcontainer">' .
......
......@@ -44,7 +44,7 @@ class question_name_text_column extends \core_question\bank\question_name_column
if ($labelfor) {
echo '<label for="' . $labelfor . '">';
}
echo quiz_question_tostring($question);
echo quiz_question_tostring($question, false, true, true, $question->tags);
if ($labelfor) {
echo '</label>';
}
......@@ -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);
}
}
......@@ -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
*/
function quiz_question_tostring($question, $showicon = false, $showquestiontext = true) {
* @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,
$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));
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment