mirror of
https://github.com/moodle/moodle.git
synced 2025-08-09 19:06:41 +02:00
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:
parent
bf7ff76bcd
commit
3ea15bcef1
2 changed files with 81 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue