Skip to content

Commit

Permalink
MDL-73335 question: Add the tertiary nav for question bank
Browse files Browse the repository at this point in the history
The tertiary navigation has been added to the question bank.
- Url selector has been added for the pages:
  Questions, Categories, Import and Export
- A separate page to "Add category" has been added.
  The "Add category" is available as a tertiary nav button.
- Updated the tests for the changes made.

This commit is mostly Sujith's work, with further changes by
Tim Hunt <T.J.Hunt@open.ac.uk> so we share the blame/credit.

AMOS BEGIN
 CPY [questioncats,mod_quiz],[questioncategories,core_question]
AMOS END
  • Loading branch information
sharidas authored and ilyatregubov committed Feb 24, 2022
1 parent 3458d15 commit b610055
Show file tree
Hide file tree
Showing 55 changed files with 339 additions and 117 deletions.
2 changes: 1 addition & 1 deletion admin/tool/recyclebin/tests/behat/backup_user_data.feature
Expand Up @@ -43,7 +43,7 @@ Feature: Backup user data
| Feedback for the response 'False'. | So you think it is false |
And I log out
When I am on the "Quiz 1" "quiz activity" page logged in as student1
And I follow "Attempt quiz"
And I press "Attempt quiz"
And I click on "True" "radio" in the "First question" "question"
And I click on "False" "radio" in the "Second question" "question"
And I press "Finish attempt"
Expand Down
2 changes: 1 addition & 1 deletion badges/tests/behat/criteria_activity.feature
Expand Up @@ -57,7 +57,7 @@ Feature: Award badges based on activity completion
And the "Receive a passing grade" completion condition of "Test quiz name" is displayed as "failed"
And the "Receive a pass grade or complete all available attempts" completion condition of "Test quiz name" is displayed as "todo"
When I am on the "Test quiz name" "quiz activity" page
And I follow "Attempt quiz"
And I press "Re-attempt quiz"
And I set the field "False" to "1"
And I press "Finish attempt ..."
And I press "Submit all and finish"
Expand Down
2 changes: 2 additions & 0 deletions lang/en/question.php
Expand Up @@ -281,6 +281,8 @@
$string['qtypeveryshort'] = 'T';
$string['questionaffected'] = '<a href="{$a->qurl}">Question "{$a->name}" ({$a->qtype})</a> is in this question category but is also being used in <a href="{$a->qurl}">quiz "{$a->quizname}"</a> in another course "{$a->coursename}".';
$string['questionbank'] = 'Question bank';
$string['questionbanknavigation'] = 'Question bank tertiary navigation';
$string['questioncategories'] = 'Question categories';
$string['questioncategory'] = 'Question category';
$string['questioncatsfor'] = 'Question categories for \'{$a}\'';
$string['questiondoesnotexist'] = 'This question does not exist';
Expand Down
2 changes: 2 additions & 0 deletions question/bank/bulkmove/move.php
Expand Up @@ -60,6 +60,8 @@
$streditingquestions = get_string('movequestions', 'qbank_bulkmove');
$PAGE->set_title($streditingquestions);
$PAGE->set_heading($COURSE->fullname);
$PAGE->activityheader->disable();
$PAGE->set_secondary_active_tab("questionbank");

if ($category) {
list($tocategoryid, $contextid) = explode(',', $category);
Expand Down
4 changes: 2 additions & 2 deletions question/bank/bulkmove/tests/behat/bulk_move.feature
Expand Up @@ -23,14 +23,14 @@ Feature: Use the qbank plugin manager page for bulkmove
And I should see "Bulk move questions"
And I click on "Disable" "link" in the "Bulk move questions" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on "First question" "checkbox"
And I click on "With selected" "button"
Then I should not see question bulk action "move"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Bulk move questions" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on "First question" "checkbox"
And I click on "With selected" "button"
And I should see question bulk action "move"
6 changes: 3 additions & 3 deletions question/bank/comment/tests/behat/question_comment.feature
Expand Up @@ -120,7 +120,7 @@ Feature: A Teacher can comment in a question
Scenario: Comments added from the quiz page are visible
Given I log in as "teacher1"
And I am on the "Test quiz" "quiz activity" page
When I navigate to "Edit quiz" in current page administration
When I navigate to "Questions" in current page administration
And I press "Add"
And I follow "from question bank"
And I click on "Select" "checkbox" in the "First question" "table_row"
Expand All @@ -133,15 +133,15 @@ Feature: A Teacher can comment in a question
And I should see "Some new comment"
And I switch to the main window
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I choose "Preview" action for "First question" in the question bank
And I click on "Comments" "link"
And I should see "Some new comment"
And I should see "T1 Teacher1"
And I delete "Some new comment" comment from question preview
And I should not see "Some new comment"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Edit quiz" in current page administration
And I navigate to "Questions" in current page administration
And I click on "Preview question" "link"
And I switch to "questionpreview" window
And I press "Comments"
Expand Down
Expand Up @@ -38,7 +38,7 @@ Feature: A teacher can edit question with custom fields
| Feedback for the response 'True'. | So you think it is true |
| Feedback for the response 'False'. | So you think it is false |
And I am on the "Test quiz name" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration

Scenario: Edit a previously created question and see the custom field in the overview table and in the question preview.
When I choose "Edit question" action for "First question" in the question bank
Expand Down
Expand Up @@ -38,7 +38,7 @@ Feature: The visibility of question custom fields control where they are display
| Feedback for the response 'True'. | So you think it is true |
| Feedback for the response 'False'. | So you think it is false |
And I am on the "Test quiz name" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration

@javascript
Scenario: Display custom question fields to teachers based on their visibility.
Expand Down
2 changes: 2 additions & 0 deletions question/bank/deletequestion/delete.php
Expand Up @@ -58,6 +58,8 @@
$streditingquestions = get_string('deletequestion', 'qbank_deletequestion');
$PAGE->set_title($streditingquestions);
$PAGE->set_heading($COURSE->fullname);
$PAGE->activityheader->disable();
$PAGE->set_secondary_active_tab("questionbank");

// Unhide a question.
if (($unhide = optional_param('unhide', '', PARAM_INT)) and confirm_sesskey()) {
Expand Down
Expand Up @@ -23,13 +23,13 @@ Feature: Use the qbank plugin manager page for deletequestion
And I should see "Delete question"
And I click on "Disable" "link" in the "Delete question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on ".dropdown-toggle" "css_element" in the "First question" "table_row"
Then I should not see "Delete" in the "region-main" "region"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Delete question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on ".dropdown-toggle" "css_element" in the "First question" "table_row"
And I should see "Delete" in the "region-main" "region"

Expand All @@ -40,21 +40,21 @@ Feature: Use the qbank plugin manager page for deletequestion
And I should see "Delete question"
And I click on "Disable" "link" in the "Delete question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on "With selected" "button"
Then I should not see question bulk action "deleteselected"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Delete question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on "With selected" "button"
And I should see question bulk action "deleteselected"

@javascript
Scenario: I should not see the deleted questions in the base view
Given I log in as "admin"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on "First question" "checkbox"
And I click on "First question second" "checkbox"
And I click on "With selected" "button"
Expand Down
Expand Up @@ -23,15 +23,15 @@ Feature: Use the qbank plugin manager page for editquestion
And I should see "Edit question"
And I click on "Disable" "link" in the "Edit question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
Then I should not see "Status"
And I click on ".dropdown-toggle" "css_element" in the "First question" "table_row"
And I should not see "Edit question" in the "region-main" "region"
And I should not see "Duplicate" in the "region-main" "region"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Edit question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on ".dropdown-toggle" "css_element" in the "First question" "table_row"
Then I should see "Status"
And I click on ".dropdown-toggle" "css_element" in the "First question" "table_row"
Expand Down
4 changes: 3 additions & 1 deletion question/bank/exportquestions/export.php
Expand Up @@ -52,7 +52,9 @@

// Print horizontal nav if needed.
$renderer = $PAGE->get_renderer('core_question', 'bank');
echo $renderer->extra_horizontal_navigation();

$qbankaction = new \core_question\output\qbank_action_menu($thispageurl);
echo $renderer->render($qbankaction);

$exportform = new export_form($thispageurl,
['contexts' => $contexts->having_one_edit_tab_cap('export'), 'defaultcategory' => $pagevars['cat']]);
Expand Down
3 changes: 2 additions & 1 deletion question/bank/importquestions/import.php
Expand Up @@ -79,8 +79,9 @@

// Print horizontal nav if needed.
$renderer = $PAGE->get_renderer('core_question', 'bank');
echo $renderer->extra_horizontal_navigation();

$qbankaction = new \core_question\output\qbank_action_menu($thispageurl);
echo $renderer->render($qbankaction);

// File upload form submitted.
if ($form = $importform->get_data()) {
Expand Down
14 changes: 9 additions & 5 deletions question/bank/managecategories/category.php
Expand Up @@ -50,11 +50,13 @@
$param->cancel = optional_param('cancel', '', PARAM_ALPHA);
$param->move = optional_param('move', 0, PARAM_INT);
$param->moveto = optional_param('moveto', 0, PARAM_INT);
$param->edit = optional_param('edit', 0, PARAM_INT);
$param->edit = optional_param('edit', null, PARAM_INT);

$url = new moodle_url($thispageurl);
foreach ((array)$param as $key => $value) {
if (($key !== 'cancel' && $value !== 0) || ($key === 'cancel' && $value !== '')) {
if (($key !== 'cancel' && $key !== 'edit' && $value !== 0) ||
($key === 'cancel' && $value !== '') ||
($key === 'edit' && $value !== null)) {
$url->param($key, $value);
}
}
Expand Down Expand Up @@ -144,7 +146,7 @@
redirect($thispageurl);
}

if ($param->edit) {
if ($param->edit !== null) {
$PAGE->navbar->add(get_string('editingcategory', 'question'));
}

Expand All @@ -156,10 +158,12 @@

// Print horizontal nav if needed.
$renderer = $PAGE->get_renderer('core_question', 'bank');
echo $renderer->extra_horizontal_navigation();

$qbankaction = new \core_question\output\qbank_action_menu($url);
echo $renderer->render($qbankaction);

// Display the UI.
if (!empty($param->edit)) {
if ($param->edit !== null) {
$qcobject->edit_single_category($param->edit);
} else if ($questionstomove) {
$qcobject->display_move_form($questionstomove, $category);
Expand Down
Expand Up @@ -71,7 +71,7 @@ protected function definition() {
$mform->addHelpButton('idnumber', 'idnumber', 'question');
$mform->setType('idnumber', PARAM_RAW);

$this->add_action_buttons(false, get_string('addcategory', 'question'));
$this->add_action_buttons(true, get_string('addcategory', 'question'));

$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
Expand Down
33 changes: 15 additions & 18 deletions question/bank/managecategories/classes/question_category_object.php
Expand Up @@ -136,7 +136,8 @@ public function initialize($page, $contexts, $currentcat, $defaultcategory, $tod
foreach ($this->editlists as $key => $list) {
list($paged, $count) = $this->editlists[$key]->list_from_records($paged, $count);
}
$this->catform = new question_category_edit_form($this->pageurl, compact('contexts', 'currentcat'));
$this->catform = new question_category_edit_form($this->pageurl,
['contexts' => $contexts, 'currentcat' => $currentcat ?? 0]);
if (!$currentcat) {
$this->catform->set_data(['parent' => $defaultcategory]);
}
Expand All @@ -147,15 +148,8 @@ public function initialize($page, $contexts, $currentcat, $defaultcategory, $tod
*
*/
public function display_user_interface(): void {

// Interface for editing existing categories.
$this->output_edit_lists();

echo \html_writer::empty_tag('br');
// Interface for adding a new category.
$this->output_new_table();
echo \html_writer::empty_tag('br');

}

/**
Expand All @@ -174,7 +168,7 @@ public function output_new_table(): void {
public function output_edit_lists(): void {
global $OUTPUT;

echo $OUTPUT->heading_with_help(get_string('editcategories', 'question'), 'editcategories', 'question');
echo $OUTPUT->heading_with_help(get_string('questioncategories', 'question'), 'editcategories', 'question');

foreach ($this->editlists as $context => $list) {
$listhtml = $list->to_html(0, ['str' => $this->str]);
Expand Down Expand Up @@ -208,26 +202,29 @@ public function get_course_ids(array $categories): array {
}

/**
* Edit a category.
* Edit a category, or add a new one if the id is zero.
*
* @param int $categoryid Category id.
*/
public function edit_single_category(int $categoryid): void {
// Interface for adding a new category.
global $DB;
// Interface for editing existing categories.
$category = $DB->get_record("question_categories", ["id" => $categoryid]);
if (empty($category)) {
throw new moodle_exception('invalidcategory', '', '', $categoryid);
} else if ($category->parent == 0) {
throw new moodle_exception('cannotedittopcat', 'question', '', $categoryid);
} else {

if ($categoryid) {
// Editing an existing category.
$category = $DB->get_record("question_categories", ["id" => $categoryid], '*', MUST_EXIST);
if ($category->parent == 0) {
throw new moodle_exception('cannotedittopcat', 'question', '', $categoryid);
}

$category->parent = "{$category->parent},{$category->contextid}";
$category->submitbutton = get_string('savechanges');
$category->categoryheader = $this->str->edit;
$this->catform->set_data($category);
$this->catform->display();
}

// Show the form.
$this->catform->display();
}

/**
Expand Down
Expand Up @@ -22,7 +22,9 @@ Feature: A teacher can move question categories in the question bank

Scenario: A question category can be moved to another context
When I follow "Test quiz"
And I navigate to "Question bank > Categories" in current page administration
And I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I follow "Add category"
And I set the following fields to these values:
| Name | Test category |
| Parent category | Top for Test quiz |
Expand All @@ -32,7 +34,9 @@ Feature: A teacher can move question categories in the question bank

Scenario: A question category can be moved to top level
When I follow "Test quiz"
And I navigate to "Question bank > Categories" in current page administration
And I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I follow "Add category"
And I set the following fields to these values:
| Name | Test category |
| Parent category | Default for Test quiz |
Expand Down
Expand Up @@ -27,7 +27,9 @@ Feature: A teacher can put questions in categories in the question bank
And I am on "Course 1" course homepage

Scenario: A new question category can be created
When I navigate to "Question bank > Categories" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I follow "Add category"
And I set the following fields to these values:
| Name | New Category 1 |
| Parent category | Top |
Expand All @@ -39,10 +41,12 @@ Feature: A teacher can put questions in categories in the question bank
And I should see "newcatidnumber"
And I should see "(0)"
And I should see "Created as a test" in the "New Category 1" "list_item"
And I follow "Add category"
And "New Category 1 [newcatidnumber]" "option" should exist in the "Parent category" "select"

Scenario: A question category can be edited
When I navigate to "Question bank > Categories" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I click on "Edit this category" "link" in the "Subcategory" "list_item"
And the field "parent" matches value "&nbsp;&nbsp;&nbsp;Default for C1"
And I set the following fields to these values:
Expand All @@ -53,14 +57,17 @@ Feature: A teacher can put questions in categories in the question bank
And I should see "I was edited" in the "New name" "list_item"

Scenario: An empty question category can be deleted
When I navigate to "Question bank > Categories" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I click on "Delete" "link" in the "Subcategory" "list_item"
Then I should not see "Subcategory"

Scenario: An non-empty question category can be deleted if you move the contents elsewhere
When I navigate to "Question bank > Categories" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I click on "Delete" "link" in the "Used category" "list_item"
And I should see "The category 'Used category' contains 1 questions"
And I press "Save in category"
Then I should not see "Used category"
And I follow "Add category"
And I should see "Default for C1 (1)"

0 comments on commit b610055

Please sign in to comment.