LMSouq
moodle-core Open

how to enroll a user in all courses on Moodle

US
user1882752
1 month ago
3 views
Problem Description
I have a Moodle with a SSO. Users sign onto a site and click on a link to come to my Moodle. When they arrive, I want to enroll them on every course on my Moodle. However, I am unable to get the sql to work. Here is what I have: $ra = new object(); $ra->roleid = 5; $ra->contextid = $contextid; $ra->userid = $user->id; $ra->hidden = 0; $ra->enrol = 'manual'; //$ra->enrol = 'self'; /// Always round timestart downto 100 secs to help DBs to use their own caching algorithms /// by repeating queries with the same exact parameters in a 100 secs time window $ra->timestart = 0; $ra->timeend = 0; $ra->timemodified = time(); $ra->modifierid = 0; // Enrol the User for the Course $ra->id = $DB->insert_record('role_assignments',$ra);

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base