Skip to content

Commit 1d69dcd

Browse files
committed
MDL-85516 assign: Include all active enrolments in participants
1 parent dcf9426 commit 1d69dcd

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

public/mod/assign/classes/notification_helper.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public static function get_users_within_assignment(int $assignmentid, string $ty
227227
$assignmentobj = self::get_assignment_data($assignmentid);
228228

229229
// Get our assignment users.
230-
$users = $assignmentobj->list_participants(0, true, false, true);
230+
$users = $assignmentobj->list_participants(0, false, false, true);
231231

232232
// If it's an overdue type and there are no submission plugins, skip the assignment.
233233
if ($type == self::TYPE_OVERDUE) {
@@ -243,6 +243,12 @@ public static function get_users_within_assignment(int $assignmentid, string $ty
243243
$completion = new \completion_info($course);
244244

245245
foreach ($users as $key => $user) {
246+
// Exclude suspended users.
247+
if ($user->suspended || ($user->auth == 'nologin')) {
248+
unset($users[$key]);
249+
continue;
250+
}
251+
246252
// Check if the user has submitted already.
247253
$submission = $assignmentobj->get_user_submission($user->id, false);
248254
if ($submission && $submission->status === ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
@@ -333,7 +339,12 @@ public static function get_users_within_assignment(int $assignmentid, string $ty
333339
}
334340
}
335341

336-
return $users;
342+
// Only the array key and user id field are required.
343+
$userids = [];
344+
foreach ($users as $key => $user) {
345+
$userids[$key] = (object) ['id' => $user->id];
346+
}
347+
return $userids;
337348
}
338349

339350
/**

public/mod/assign/locallib.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,9 +2402,6 @@ public function list_participants($currentgroup, $idsonly, $tablesort = false, ?
24022402
}
24032403
}
24042404

2405-
// Exclude suspended users from the list of participants.
2406-
$additionalfilters .= " AND u.suspended = 0 AND u.auth <> 'nologin'";
2407-
24082405
$sql = "SELECT $fields
24092406
FROM {user} u
24102407
JOIN ($esql UNION $ssql) je ON je.id = u.id

public/mod/assign/tests/locallib_test.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,16 +1005,19 @@ public function test_list_participants_activeenrol(): void {
10051005
$this->getDataGenerator()->create_and_enrol($course, 'student');
10061006
}
10071007

1008-
// Create 10 suspended students.
1008+
// Create 10 students with suspended enrolments.
10091009
for ($i = 0; $i < 10; $i++) {
10101010
$this->getDataGenerator()->create_and_enrol($course, 'student', null, 'manual', 0, 0, ENROL_USER_SUSPENDED);
10111011
}
10121012

1013+
// Create a student with an active enrolment and suspended account.
1014+
$this->getDataGenerator()->create_and_enrol($course, 'student', ['suspended' => 1]);
1015+
10131016
$this->setUser($teacher);
10141017
set_user_preference('grade_report_showonlyactiveenrol', false);
10151018
$assign = $this->create_instance($course, ['grade' => 100]);
10161019

1017-
$this->assertCount(10, $assign->list_participants(null, true));
1020+
$this->assertCount(11, $assign->list_participants(0, true));
10181021
}
10191022

10201023
public function test_list_participants_with_group_restriction(): void {

0 commit comments

Comments
 (0)