Commit c185e4fe authored by Shamim Rezaie's avatar Shamim Rezaie
Browse files

MDL-61589 Questions: Top question category naming improvement

Display the context name next to the top question category name.
parent 1287039e
...@@ -290,6 +290,7 @@ $string['stoponerror'] = 'Stop on error'; ...@@ -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['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['tofilecategory'] = 'Write category to file';
$string['tofilecontext'] = 'Write context to file'; $string['tofilecontext'] = 'Write context to file';
$string['topfor'] = 'Top for {$a}';
$string['uninstallbehaviour'] = 'Uninstall this question behaviour.'; $string['uninstallbehaviour'] = 'Uninstall this question behaviour.';
$string['uninstallqtype'] = 'Uninstall this question type.'; $string['uninstallqtype'] = 'Uninstall this question type.';
$string['unknown'] = 'Unknown'; $string['unknown'] = 'Unknown';
......
...@@ -6548,15 +6548,16 @@ function question_add_tops($categories, $pcontexts) { ...@@ -6548,15 +6548,16 @@ function question_add_tops($categories, $pcontexts) {
DEBUG_DEVELOPER); DEBUG_DEVELOPER);
$topcats = array(); $topcats = array();
foreach ($pcontexts as $context) { foreach ($pcontexts as $contextid) {
$topcat = question_get_top_category($context, true); $topcat = question_get_top_category($contextid, true);
$context = context::instance_by_id($contextid);
$newcat = new stdClass(); $newcat = new stdClass();
$newcat->id = "{$topcat->id},$context"; $newcat->id = "{$topcat->id},$contextid";
$newcat->name = get_string('top'); $newcat->name = get_string('topfor', 'question', $context->get_context_name(false));
$newcat->parent = 0; $newcat->parent = 0;
$newcat->contextid = $context; $newcat->contextid = $contextid;
$topcats["{$topcat->id},$context"] = $newcat; $topcats["{$topcat->id},$contextid"] = $newcat;
} }
// Put topcats in at beginning of array - they'll be sorted into different contexts later. // Put topcats in at beginning of array - they'll be sorted into different contexts later.
return array_merge($topcats, $categories); return array_merge($topcats, $categories);
......
...@@ -1422,7 +1422,8 @@ function question_fix_top_names($categories) { ...@@ -1422,7 +1422,8 @@ function question_fix_top_names($categories) {
foreach ($categories as $id => $category) { foreach ($categories as $id => $category) {
if ($category->parent == 0) { 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));
} }
} }
......
...@@ -20,13 +20,12 @@ Feature: A teacher can move question categories in the question bank ...@@ -20,13 +20,12 @@ Feature: A teacher can move question categories in the question bank
And I log in as "teacher1" And I log in as "teacher1"
And I am on "Course 1" course homepage And I am on "Course 1" course homepage
@javascript
Scenario: A question category can be moved to another context Scenario: A question category can be moved to another context
When I follow "Test quiz" When I follow "Test quiz"
And I navigate to "Categories" node in "Quiz administration > Question bank" And I navigate to "Categories" node in "Quiz administration > Question bank"
And I click on "Parent category" "field" And I set the following fields to these values:
And I click on "//optgroup[@label='Quiz: Test quiz']//option[normalize-space(text())='Top']" "xpath_element" | Name | Test category |
And I set the field "Name" to "Test category" | Parent category | Top for Test quiz |
And I press "submitbutton" And I press "submitbutton"
And I click on "Share in context for Course: Course 1" "link" in the "Test category" "list_item" 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" Then I should see "Test category" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' questioncategories ') and contains(concat(' ', normalize-space(@class), ' '), ' contextlevel50 ')]" "xpath_element"
......
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