Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions classes/task/issue_certificates_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ public function execute() {
$filteredusers = $infomodule->filter_user_list($userswithissueview);

foreach ($filteredusers as $filtereduser) {
// Do not issue certs to suspended users.
if ($filtereduser->suspended) {
continue;
}

// Skip if the user has already been issued and emailed.
if (in_array($filtereduser->id, array_keys((array)$issuedusers))) {
continue;
Expand Down
14 changes: 10 additions & 4 deletions tests/email_certificate_task_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,20 @@ public function test_email_certificates_students(): void {
// Create some users.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user(['firstname' => 'Teacher', 'lastname' => 'One']);
$user3 = $this->getDataGenerator()->create_user();
$user4 = $this->getDataGenerator()->create_user(['firstname' => 'Teacher', 'lastname' => 'One']);

// Enrol two of them in the course as students.
// Enrol three of them in the course as students.
$roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
$this->getDataGenerator()->enrol_user($user3->id, $course->id);

// Enrol one of the users as a teacher.
$this->getDataGenerator()->enrol_user($user3->id, $course->id, $roleids['editingteacher']);
$this->getDataGenerator()->enrol_user($user4->id, $course->id, $roleids['editingteacher']);

// Suspend one of the users.
$DB->set_field('user', 'suspended', '1', ['id' => $user3->id]);

// Create a custom certificate.
$customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id,
Expand Down Expand Up @@ -199,10 +204,11 @@ public function test_email_certificates_students(): void {
$issues = $DB->get_records('customcert_issues');
$this->assertCount(2, $issues);

// Confirm that it was marked as emailed and was not issued to the teacher.
// Confirm that it was marked as emailed and was not issued to the teacher or suspended student.
foreach ($issues as $issue) {
$this->assertEquals(1, $issue->emailed);
$this->assertNotEquals($user3->id, $issue->userid);
$this->assertNotEquals($user4->id, $issue->userid);
}

// Confirm that we sent out emails to the two users.
Expand Down
Loading