MDL-81741 mod_feedback: Create a new 'Questions' secondary menu item

This commit is contained in:
Mikel Martín 2024-04-23 15:32:34 +02:00
parent bcd8e0d6ed
commit 95f4f55648
17 changed files with 39 additions and 92 deletions

View File

@ -34,50 +34,14 @@ class secondary extends core_secondary {
protected function get_default_module_mapping(): array {
$basenodes = parent::get_default_module_mapping();
$basenodes[self::TYPE_CUSTOM] += [
'templatenode' => 12,
'mapcourse' => 13,
'feedbackanalysis' => 14,
'responses' => 15,
'nonrespondents' => 15.1
'questionnode' => 2,
'templatenode' => 3,
'responses' => 4,
'nonrespondents' => 4.1,
'feedbackanalysis' => 5,
'mapcourse' => 12,
];
return $basenodes;
}
/**
* Custom module construct for feedback
*
* @param settings_navigation $settingsnav The settings navigation object related to the module page
* @param navigation_node|null $rootnode The node where the module navigation nodes should be added into as children.
* If not explicitly defined, the nodes will be added to the secondary root
* node by default.
*/
protected function load_module_navigation(settings_navigation $settingsnav, ?navigation_node $rootnode = null): void {
$rootnode = $rootnode ?? $this;
$mainnode = $settingsnav->find('modulesettings', self::TYPE_SETTING);
$nodes = $this->get_default_module_mapping();
if ($mainnode) {
$url = new \moodle_url('/mod/' . $this->page->activityname . '/view.php', ['id' => $this->page->cm->id]);
$setactive = $url->compare($this->page->url, URL_MATCH_BASE);
$node = $rootnode->add(get_string('modulename', 'feedback'), $url, null, null, 'modulepage');
if ($setactive) {
$node->make_active();
}
// Add the initial nodes.
$nodesordered = $this->get_leaf_nodes($mainnode, $nodes);
$this->add_ordered_nodes($nodesordered, $rootnode);
// Reorder the existing nodes in settings so the active node scan can pick it up.
$existingnode = $settingsnav->find('questionnode', self::TYPE_CUSTOM);
if ($existingnode) {
$node->add_node($existingnode);
$nodes[self::TYPE_CUSTOM] += ['questionnode' => 3];
}
// We have finished inserting the initial structure.
// Populate the menu with the rest of the nodes available.
$this->load_remaining_nodes($mainnode, $nodes, $rootnode);
}
}
}

View File

@ -39,6 +39,7 @@ if ($action !== false) {
$url->param('action', $action);
}
$PAGE->set_url($url);
navigation_node::override_active_url(new moodle_url('/mod/feedback/edit.php'));
if (! $cm = get_coursemodule_from_id('feedback', $id)) {
throw new \moodle_exception('invalidcoursemodule');

View File

@ -2822,16 +2822,9 @@ function feedback_extend_settings_navigation(settings_navigation $settings, navi
}
if (has_capability('mod/feedback:edititems', $context)) {
$questionnode = $feedbacknode->add(get_string('questions', 'feedback'), null,
$feedbacknode->add(get_string('questions', 'feedback'),
new moodle_url('/mod/feedback/edit.php', ['id' => $settings->get_page()->cm->id]),
navigation_node::TYPE_CUSTOM, null, 'questionnode');
$questionnode->add(get_string('edit_items', 'feedback'),
new moodle_url('/mod/feedback/edit.php', ['id' => $settings->get_page()->cm->id]));
$questionnode->add(get_string('export_questions', 'feedback'),
new moodle_url('/mod/feedback/export.php', ['id' => $settings->get_page()->cm->id, 'action' => 'exportfile']));
$questionnode->add(get_string('import_questions', 'feedback'),
new moodle_url('/mod/feedback/import.php', ['id' => $settings->get_page()->cm->id]));
$feedbacknode->add(get_string('templates', 'feedback'),
new moodle_url('/mod/feedback/manage_templates.php', ['id' => $settings->get_page()->cm->id, 'mode' => 'manage']),

View File

@ -44,11 +44,6 @@ if ($mode) {
$params += ['mode' => $mode];
}
$url = new moodle_url('/mod/feedback/manage_templates.php', $params);
if ($mode == 'manage') {
navigation_node::override_active_url($url);
} else {
navigation_node::override_active_url(new moodle_url('/mod/feedback/view.php', $params));
}
$PAGE->set_url($url);
$actionbar = new \mod_feedback\output\edit_action_bar($cm->id, $url);

View File

@ -29,7 +29,7 @@ Feature: Anonymous feedback
When I log in as "manager"
And I am on site homepage
And I follow "Site feedback"
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Multiple choice" question to the feedback with:
| Question | Do you like our site? |
| Label | multichoice2 |
@ -156,7 +156,7 @@ Feature: Anonymous feedback
Scenario: Anonymous feedback in a course
# Teacher can not
When I am on the "Course feedback" "feedback activity" page logged in as teacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Multiple choice" question to the feedback with:
| Question | Do you like this course? |
| Label | multichoice1 |

View File

@ -43,7 +43,7 @@ Feature: Mapping courses in a feedback
When I log in as "manager"
And I am on site homepage
And I follow "Course feedback"
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Information" question to the feedback with:
| Question | this is an information question |
| Label | info |
@ -132,7 +132,7 @@ Feature: Mapping courses in a feedback
And I log in as "manager"
And I am on site homepage
And I follow "Course feedback"
And I follow "Mapped courses"
And I navigate to "Mapped courses" in current page administration
And I set the field "Courses" to "Course 2, Course 3"
And I press "Save changes"
And I should see "Course mapping has been changed"

View File

@ -23,7 +23,7 @@ Feature: Exporting and importing feedbacks
Scenario: Export sample feedback and compare with the fixture
When I am on the "Learning experience" "feedback activity" page logged in as teacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And "Export questions" "link" should not exist in the ".tertiary-navigation" "css_element"
And I add a "Information" question to the feedback with:
| Question | this is an information question |
@ -73,7 +73,7 @@ Feature: Exporting and importing feedbacks
@javascript @_file_upload
Scenario: Import feedback deleting old items
When I am on the "Learning experience" "feedback activity" page logged in as teacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Numeric answer" question to the feedback with:
| Question | Existing question |
| Label | numeric |
@ -96,7 +96,7 @@ Feature: Exporting and importing feedbacks
@javascript @_file_upload
Scenario: Import feedback appending new items
When I am on the "Learning experience" "feedback activity" page logged in as teacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Numeric answer" question to the feedback with:
| Question | Existing question |
| Label | numeric |

View File

@ -26,7 +26,7 @@ Feature: View activity completion in the feedback activity
| completionview | 1 |
| completionsubmit | 1 |
And I am on the "Music history" "feedback activity" page logged in as teacher1
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Multiple choice" question to the feedback with:
| Question | What is your favourite instrument |
| Label | instrument1 |

View File

@ -22,7 +22,7 @@ Feature: Testing multichoice questions in feedback
| activity | name | course | idnumber |
| feedback | Learning experience | C1 | feedback0 |
And I am on the "Learning experience" "feedback activity" page logged in as teacher1
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
@javascript
Scenario: Non-rated single-answer multiple choice questions in feedback
@ -150,7 +150,7 @@ Feature: Testing multichoice questions in feedback
And I should see "1 (100.00 %)" in the "option i" "table_row"
# Change the settings so we don't analyse empty submits
And I am on the "Learning experience" "feedback activity" page
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I open the action menu in "//div[contains(@class, 'feedback_itemlist') and contains(.,'multichoice1')]" "xpath_element"
And I choose "Edit question" in the open action menu
And I set the field "Omit empty submits in analysis" to "Yes"
@ -290,7 +290,7 @@ Feature: Testing multichoice questions in feedback
And I should see "1 (100.00 %)" in the "option i" "table_row"
# Change the settings so we don't analyse empty submits
And I am on the "Learning experience" "feedback activity" page
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I open the action menu in "//div[contains(@class, 'feedback_itemlist') and contains(.,'multichoice1')]" "xpath_element"
And I choose "Edit question" in the open action menu
And I set the field "Omit empty submits in analysis" to "Yes"
@ -409,7 +409,7 @@ Feature: Testing multichoice questions in feedback
And I should see "1 (100.00 %)" in the "option i" "table_row"
# Change the settings so we don't analyse empty submits
And I am on the "Learning experience" "feedback activity" page
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I open the action menu in "//div[contains(@class, 'feedback_itemlist') and contains(.,'multichoice1')]" "xpath_element"
And I choose "Edit question" in the open action menu
And I set the field "Omit empty submits in analysis" to "Yes"

View File

@ -27,7 +27,7 @@ Feature: Non anonymous feedback with multiple submissions
When I log in as "teacher"
And I am on "Course 1" course homepage
And I follow "Course feedback"
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Short text answer" question to the feedback with:
| Question | first |
| Label | shorttext1 |

View File

@ -27,7 +27,7 @@ Feature: Non anonymous feedback
| feedback | Site feedback | Acceptance test site | feedback0 | 2 | 1 | 1 |
| feedback | Course feedback | C1 | feedback1 | 2 | 1 | 0 |
When I am on the "Site feedback" "feedback activity" page logged in as manager
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Multiple choice" question to the feedback with:
| Question | Do you like our site? |
| Label | multichoice2 |
@ -91,7 +91,7 @@ Feature: Non anonymous feedback
@javascript
Scenario: Non anonymous feedback in a course
When I am on the "Course feedback" "feedback activity" page logged in as teacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Multiple choice" question to the feedback with:
| Question | Do you like this course? |
| Label | multichoice1 |

View File

@ -22,7 +22,7 @@ Feature: Preview feedback questions
| activity | name | course | idnumber |
| feedback | Music history | C1 | feedback0 |
And I am on the "Music history" "feedback activity" page logged in as editingteacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Multiple choice" question to the feedback with:
| Question | What is your favourite instrument |
| Label | instrument1 |

View File

@ -23,7 +23,7 @@ Feature: Test creating different types of feedback questions for anonymous feedb
| activity | name | course | idnumber |
| feedback | Learning experience | C1 | feedback0 |
When I am on the "Learning experience" "feedback activity" page logged in as teacher1
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Information" question to the feedback with:
| Question | this is an information question |
| Label | info |

View File

@ -23,7 +23,7 @@ Feature: Test creating different types of feedback questions for non-anonymous f
| activity | name | course | idnumber | anonymous |
| feedback | Learning experience | C1 | feedback0 | 2 |
When I am on the "Learning experience" "feedback activity" page logged in as teacher1
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Information" question to the feedback with:
| Question | this is an information question |
| Label | info |

View File

@ -43,7 +43,7 @@ Feature: Show users who have not responded to the feedback survey
| Record user names | User's name will be logged and shown with answers |
| Access restrictions | Grouping: GX1 |
And I am on the Frogs "feedback activity" page
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Short text answer" question to the feedback with:
| Question | Y/N? |
And I log out

View File

@ -26,7 +26,7 @@ Feature: Saving, using and deleting feedback templates
| feedback | Another feedback in course 1 | C1 | feedback2 |
| feedback | Learning experience course 2 | C2 | feedback3 |
And I am on the "Learning experience course 1" "feedback activity" page logged in as teacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Multiple choice" question to the feedback with:
| Question | this is a multiple choice 1 |
| Label | multichoice1 |
@ -38,7 +38,7 @@ Feature: Saving, using and deleting feedback templates
Scenario: Teacher can save template and re-use it in the same course only
# Go to feedback templates and make sure none exist yet
When I am on the "Learning experience course 1" "feedback activity" page logged in as teacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I select "Use a template" from the "jump" singleselect
Then I should see "No templates available yet"
And "Use a template" "field" should not exist
@ -55,7 +55,7 @@ Feature: Saving, using and deleting feedback templates
And I should see "My first template"
# Create a feedback from this template in the same course
And I am on the "Another feedback in course 1" "feedback activity" page
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I select "Use a template" from the "jump" singleselect
And I follow "My first template"
And I should see "this is a multiple choice 1"
@ -64,7 +64,7 @@ Feature: Saving, using and deleting feedback templates
And I should see "this is a multiple choice 1"
# Make sure this template is not available in another course
And I am on the "Learning experience course 2" "feedback activity" page
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I select "Use a template" from the "jump" singleselect
And I should see "No templates available yet"
And I log out
@ -73,7 +73,7 @@ Feature: Saving, using and deleting feedback templates
Scenario: Teacher can append template to existing questions or remove them
# Save feedback as a course template
When I am on the "Learning experience course 1" "feedback activity" page logged in as teacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I press "Save as new template"
And I should see "Save as new template" in the ".modal-title" "css_element"
And I should see "Name" in the ".modal-body" "css_element"
@ -82,7 +82,7 @@ Feature: Saving, using and deleting feedback templates
And I press "Save as new template"
# Add questions to another feedback
And I am on the "Another feedback in course 1" "feedback activity" page
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I add a "Multiple choice" question to the feedback with:
| Question | What is your favourite subject |
| Label | subjectchoice |
@ -108,14 +108,14 @@ Feature: Saving, using and deleting feedback templates
@javascript
Scenario: Manager can save template as public and it will be available in any course
When I am on the "Learning experience course 1" "feedback activity" page logged in as manager
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I press "Save as new template"
And I set the field "Name" to "My first template"
And I set the field "Public" to "1"
And I click on "Save" "button" in the ".modal-dialog" "css_element"
And I log out
And I am on the "Learning experience course 2" "feedback activity" page logged in as teacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I select "Use a template" from the "jump" singleselect
And I follow "My first template"
And I should see "this is a multiple choice 1"
@ -129,7 +129,7 @@ Feature: Saving, using and deleting feedback templates
Scenario: Teacher can delete course templates but can not delete public templates
# Save feedback as both public and course template
When I am on the "Learning experience course 1" "feedback activity" page logged in as manager
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I press "Save as new template"
And I set the field "Name" to "My public template"
And I set the field "Public" to "1"
@ -140,7 +140,7 @@ Feature: Saving, using and deleting feedback templates
And I log out
# Login as teacher and try to delete templates
And I am on the "Another feedback in course 1" "feedback activity" page logged in as teacher
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I select "Use a template" from the "jump" singleselect
And I follow "My public template"
Then I should not see "Delete"
@ -158,7 +158,7 @@ Feature: Saving, using and deleting feedback templates
Scenario: Manager can delete both course and public templates
# Save feedback as both public and course template
When I am on the "Learning experience course 1" "feedback activity" page logged in as manager
And I click on "Edit questions" "link" in the "[role=main]" "css_element"
And I navigate to "Questions" in current page administration
And I press "Save as new template"
And I set the field "Name" to "My public template"
And I set the field "Public" to "1"

View File

@ -55,12 +55,6 @@ $params += ($mode ? ['mode' => $mode] : []);
$activeurl = new moodle_url('/mod/feedback/manage_templates.php', $params);
$PAGE->set_url($activeurl);
if ($mode == 'manage') {
navigation_node::override_active_url($activeurl);
} else {
navigation_node::override_active_url(new moodle_url('/mod/feedback/view.php', $params));
}
$PAGE->set_heading($course->fullname);
$PAGE->set_title($feedback->name);
$PAGE->activityheader->set_attrs([