Hi Giovanni,
Sure. The bones of my plugin is as follows:
Create a user (you should have some logic that validates the user doesn't already exist):
Sure. The bones of my plugin is as follows:
Create a user (you should have some logic that validates the user doesn't already exist):
$newuser = new stdClass();
$newuser->username = $username;
$newuser->password = $password_hashed;
$newuser->firstname = $firstname;
$newuser->lastname = $lastname;
$newuser->email = $email;
$newuser->auth = 'manual';
$newuser->confirmed = 1;
$newuser->institution = $institution;
$newuser->mnethostid = 1;
$newuser->city = $city;
$newuser->country = $country;
$newuser->timecreated = time();
$newuser->timemodified = time();
$newuser->description = '';
$resp = $DB->insert_record('user',$newuser);
Enrol the user in a course:
$timestart = time();
$duration = 7;
$timeend = time()+($duration*86400); //7 days
$role = 5 //This is for a student - better to do a DB call to get though
$enrolid = whichever entry in the database equates to your course + method (e.g. courseid and 'manual');
$thisenrol = $DB->get_record('enrol',array('id'=>$enrolid));
$plugin->enrol_user($thisenrol,$userid,$role,$timestart,$timeend);
If you're just starting out to develop your own plugin, I can recommend the following Udemy course:
I found it very helpful.
Best,
Jeff