From c185e4fe2168c19beecb7e72757a199cd612de1d Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Thu, 15 Mar 2018 18:47:25 +1100 Subject: [PATCH] MDL-61589 Questions: Top question category naming improvement Display the context name next to the top question category name. --- lang/en/question.php | 1 + lib/deprecatedlib.php | 13 +++++++------ lib/questionlib.php | 3 ++- .../tests/behat/move_question_categories.feature | 7 +++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lang/en/question.php b/lang/en/question.php index ead22db12b3..90b5b8f834a 100644 --- a/lang/en/question.php +++ b/lang/en/question.php @@ -290,6 +290,7 @@ $string['stoponerror'] = 'Stop on error'; $string['stoponerror_help'] = 'This setting determines whether the import process stops when an error is detected, resulting in no questions being imported, or whether any questions containing errors are ignored and any valid questions are imported.'; $string['tofilecategory'] = 'Write category to file'; $string['tofilecontext'] = 'Write context to file'; +$string['topfor'] = 'Top for {$a}'; $string['uninstallbehaviour'] = 'Uninstall this question behaviour.'; $string['uninstallqtype'] = 'Uninstall this question type.'; $string['unknown'] = 'Unknown'; diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 9528c100cf7..132eb55d84e 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -6548,15 +6548,16 @@ function question_add_tops($categories, $pcontexts) { DEBUG_DEVELOPER); $topcats = array(); - foreach ($pcontexts as $context) { - $topcat = question_get_top_category($context, true); + foreach ($pcontexts as $contextid) { + $topcat = question_get_top_category($contextid, true); + $context = context::instance_by_id($contextid); $newcat = new stdClass(); - $newcat->id = "{$topcat->id},$context"; - $newcat->name = get_string('top'); + $newcat->id = "{$topcat->id},$contextid"; + $newcat->name = get_string('topfor', 'question', $context->get_context_name(false)); $newcat->parent = 0; - $newcat->contextid = $context; - $topcats["{$topcat->id},$context"] = $newcat; + $newcat->contextid = $contextid; + $topcats["{$topcat->id},$contextid"] = $newcat; } // Put topcats in at beginning of array - they'll be sorted into different contexts later. return array_merge($topcats, $categories); diff --git a/lib/questionlib.php b/lib/questionlib.php index eb99d4f383a..85b34821b07 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1422,7 +1422,8 @@ function question_fix_top_names($categories) { foreach ($categories as $id => $category) { if ($category->parent == 0) { - $categories[$id]->name = get_string('top'); + $context = context::instance_by_id($category->contextid); + $categories[$id]->name = get_string('topfor', 'question', $context->get_context_name(false)); } } diff --git a/question/tests/behat/move_question_categories.feature b/question/tests/behat/move_question_categories.feature index d08eb504897..b48db72657c 100644 --- a/question/tests/behat/move_question_categories.feature +++ b/question/tests/behat/move_question_categories.feature @@ -20,13 +20,12 @@ Feature: A teacher can move question categories in the question bank And I log in as "teacher1" And I am on "Course 1" course homepage - @javascript Scenario: A question category can be moved to another context When I follow "Test quiz" And I navigate to "Categories" node in "Quiz administration > Question bank" - And I click on "Parent category" "field" - And I click on "//optgroup[@label='Quiz: Test quiz']//option[normalize-space(text())='Top']" "xpath_element" - And I set the field "Name" to "Test category" + And I set the following fields to these values: + | Name | Test category | + | Parent category | Top for Test quiz | And I press "submitbutton" And I click on "Share in context for Course: Course 1" "link" in the "Test category" "list_item" Then I should see "Test category" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' questioncategories ') and contains(concat(' ', normalize-space(@class), ' '), ' contextlevel50 ')]" "xpath_element"