Enroll user to some course

Enroll user to some course

by Max Milov -
Number of replies: 3

Hello!


I want enroll user to some course with API. Jow I can do it, simply way ?

Average of ratings: -
In reply to Max Milov

Re: Enroll user to some course

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

        $instance = $DB->get_record('enrol', array('id' => $id, 'enrol' => '...'), '*', MUST_EXIST);
        $plugin = enrol_get_plugin('...');
        $plugin->enrol_user($instance, $userid, $roleid, $timestart, $timeend);

In reply to Renaat Debleu

Re: Enroll user to some course

by Max Milov -
Thanks, it work!

Where I can find API documentation about this functions ?

In reply to Max Milov

Re: Enroll user to some course

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

This is not documented (yet).  The best information is found in the code:

    /**
     * Enrol user into course via enrol instance.
     *
     * @param stdClass $instance
     * @param int $userid
     * @param int $roleid optional role id
     * @param int $timestart 0 means unknown
     * @param int $timeend 0 means forever
     * @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
     * @param bool $recovergrades restore grade history
     * @return void
     */
    public function enrol_user(stdClass $instance, $userid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) { ....