What are the PHP functions to add/remove a course for a user?

What are the PHP functions to add/remove a course for a user?

by dirty slit -
Number of replies: 1
pretty basic questions:

What is the PHP function to add a course for a user?


and also, what is the PHP function to delete a course for a user?




P.S. Please include any other PHP functions on this topic that you think might be useful for me dealing with courses and permissions and users.
Average of ratings: -
In reply to dirty slit

Re: What are the PHP functions to add/remove a course for a user?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The way to answer this sort of question for your self is as follows:

1. How do you do this using the Moodle interface?

(Answer, you click on the Assign Roles link in the course admin block, then choose a role to assign.)

2. So, which PHP script is involved?

(Looking in the URL bar, we see that the assign roles UI is admin/roles/assign.php?roleid=5&contextid=..., that is http://cvs.moodle.org/moodle/admin/roles/assign.php?view=markup&pathrev=MOODLE_19_STABLE)

3. Looking at that code, which function does it call?

(Answer: somewhere under the // Process incoming role assignment comment, there is a call to role_assign.)