MDL-43820 enrol_guest: Override find_instance

For guest enrol method there can be just one instance.
So we can just match by type
This commit is contained in:
Ilya Tregubov 2023-08-01 11:38:00 +08:00
parent bf7ff76bcd
commit 3ea15bcef1
No known key found for this signature in database
GPG key ID: 0F58186F748E55C1
2 changed files with 81 additions and 0 deletions

View file

@ -497,6 +497,28 @@ class enrol_guest_plugin extends enrol_plugin {
public function is_csv_upload_supported(): bool {
return true;
}
/**
* Finds matching instances for a given course.
*
* @param array $enrolmentdata enrolment data.
* @param int $courseid Course ID.
* @return stdClass|null Matching instance
*/
public function find_instance(array $enrolmentdata, int $courseid) : ?stdClass {
$instances = enrol_get_instances($courseid, false);
$instance = null;
foreach ($instances as $i) {
if ($i->enrol == 'guest') {
// There can be only one guest enrol instance so find first available.
$instance = $i;
break;
}
}
return $instance;
}
}
/**