MDL-82381 report: Show group select in all courses

This commit is contained in:
Stefan Hanauska
2025-04-18 07:05:50 +02:00
parent c576443111
commit ee6fcd3953
4 changed files with 99 additions and 4 deletions
@@ -0,0 +1,5 @@
issueNumber: MDL-82381
notes:
report_progress:
- message: Added a new optional parameter $activegroup to render_groups_select()
type: changed
+21 -2
View File
@@ -77,12 +77,31 @@ class renderer extends plugin_renderer_base {
*
* @param \moodle_url $url The base url.
* @param \stdClass $course Current course.
* @param int $activegroup Currently active group, defaults to 0. Has no effect if course is in separate groups mode.
* @return string HTML
*/
public function render_groups_select(\moodle_url $url, \stdClass $course): string {
public function render_groups_select(\moodle_url $url, \stdClass $course, int $activegroup = 0): string {
global $USER;
$groupurl = fullclone($url);
$groupurl->remove_params(['page', 'group']);
$groupoutput = groups_print_course_menu($course, $groupurl, true);
$groupoutput = '';
if ($course->groupmode == SEPARATEGROUPS) {
$groupoutput = groups_print_course_menu($course, $groupurl, true);
} else {
if (has_capability('moodle/site:accessallgroups', \context_course::instance($course->id))) {
$groups = groups_get_all_groups($course->id);
} else {
$groups = groups_get_all_groups($course->id, $USER->id);
}
if (count($groups) == 0) {
return '';
}
$groupsmenu = [get_string('allparticipants')] + groups_list_to_menu($groups);
$select = new single_select($groupurl, 'group', $groupsmenu, $activegroup, null, 'selectgroup');
$select->label = get_string('groups');
$groupoutput = $this->output->render($select);
}
if (empty($groupoutput)) {
return $groupoutput;
+11 -2
View File
@@ -108,7 +108,16 @@ require_login($course);
require_capability('report/progress:view',$context);
// Get group mode
$group = groups_get_course_group($course,true); // Supposed to verify group
if ($course->groupmode == SEPARATEGROUPS) {
$group = groups_get_course_group($course, true); // Supposed to verify group.
} else {
if (groups_group_visible($groupid, $course)) {
$group = $groupid;
} else {
$group = 0;
}
}
if ($group===0 && $course->groupmode==SEPARATEGROUPS) {
require_capability('moodle/site:accessallgroups',$context);
}
@@ -205,7 +214,7 @@ if ($csv && $grandtotal && count($activities)>0) { // Only show CSV if there are
$PAGE->requires->js_call_amd('report_progress/completion_override', 'init', [fullname($USER)]);
// Handle groups (if enabled).
echo $output->render_groups_select($url, $course);
echo $output->render_groups_select($url, $course, $group);
// Display include activity filter.
echo $output->render_include_activity_select($url, $activitytypes, $activityinclude);
@@ -0,0 +1,62 @@
@report @report_progress
Feature: Teacher can view and filter activity completion data by group if group mode is not set.
Background:
Given the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
| format | topics |
| enablecompletion | 1 |
| groupmode | 0 |
| initsections | 1 |
And the following "activities" exist:
| activity | name | intro | course | idnumber | section | completion | completionview |
| quiz | My quiz B | A3 desc | C1 | quizb | 0 | 2 | 1 |
| quiz | My quiz A | A3 desc | C1 | quiza | 1 | 2 | 1 |
| page | My page | A4 desc | C1 | page1 | 2 | 2 | 1 |
| assign | My assignment | A1 desc | C1 | assign1 | 2 | 2 | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | One | teacher1@example.com |
| student1 | Student | One | student1@example.com |
| student2 | Student | Two | student2@example.com |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
| Group 2 | C1 | G2 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
And the following "group members" exist:
| user | group |
| student1 | G1 |
| student2 | G2 |
| teacher1 | G1 |
| teacher1 | G2 |
@javascript
Scenario: Teacher can view the activity completion report using filtering and sorting options.
Given I am on the "Course 1" course page logged in as "teacher1"
When I navigate to "Reports" in current page administration
And I click on "Activity completion" "link"
Then "My quiz B" "link" should appear before "My quiz A" "link" in the "completion-progress" "table"
And I set the field "Groups" to "Group 1"
And I set the field "Include" to "Quizzes"
And I set the field "Activity order" to "Alphabetical"
And "My quiz A" "link" should appear before "My quiz B" "link" in the "completion-progress" "table"
And I should not see "My assignment" in the "completion-progress" "table"
And I should not see "My page" in the "completion-progress" "table"
And I should see "Student One" in the "completion-progress" "table"
And I should not see "Student Two" in the "completion-progress" "table"
And I set the field "Groups" to "All participants"
And I set the field "Include" to "All activities and resources"
And I set the field "Section" to "Section 1"
And I should not see "My assignment" in the "completion-progress" "table"
And I should not see "My page" in the "completion-progress" "table"
And I should not see "My assignment" in the "completion-progress" "table"
And I should not see "My quiz B" in the "completion-progress" "table"
And I should see "My quiz A" in the "completion-progress" "table"
And I should see "Quiz" in the "activityinclude" "select"
And I should not see "Page" in the "activityinclude" "select"