MDL-52558 Data generator: enrol_user should allow shortname

This commit is contained in:
sam marshall
2015-12-18 11:01:30 +00:00
parent 6ace0f59ae
commit bde99c5a4b
2 changed files with 18 additions and 2 deletions
+10 -2
View File
@@ -895,7 +895,7 @@ EOD;
*
* @param int $userid
* @param int $courseid
* @param int $roleid optional role id, use only with manual plugin
* @param int|string $roleidorshortname optional role id or role shortname, use only with manual plugin
* @param string $enrol name of enrol plugin,
* there must be exactly one instance in course,
* it must support enrol_user() method.
@@ -904,9 +904,17 @@ EOD;
* @param int $status (optional) default to ENROL_USER_ACTIVE for new enrolments
* @return bool success
*/
public function enrol_user($userid, $courseid, $roleid = null, $enrol = 'manual', $timestart = 0, $timeend = 0, $status = null) {
public function enrol_user($userid, $courseid, $roleidorshortname = null, $enrol = 'manual',
$timestart = 0, $timeend = 0, $status = null) {
global $DB;
// If role is specified by shortname, convert it into an id.
if (!is_numeric($roleidorshortname) && is_string($roleidorshortname)) {
$roleid = $DB->get_field('role', 'id', array('shortname' => $roleidorshortname), MUST_EXIST);
} else {
$roleid = $roleidorshortname;
}
if (!$plugin = enrol_get_plugin($enrol)) {
return false;
}