what happens when a user enrols a course

what happens when a user enrols a course

ahmet yildirim -
Number of replies: 5
Hello,
I have a web site which is in front of the moodle.
I am taking registers from my own site.
But i need to konw what happens when a user enrols him into a course in moodle?

Because i am trying to do this job whith my own scripts.
Which fields in the database ara updated when a user enrols a course?

thanks from now... menemene
Ngā whakawākanga toharite: -
In reply to ahmet yildirim

Re: what happens when a user enrols a course

Myles Carrick -
hi Ahmet,

Mate I suspect that directly accessing Moodle's database tables is the last thing you want to be doing.

If you're looking to enrol students from an external system you want to check out the use of enrolment plugins (http://docs.moodle.org/en/Enrolment_plugins)... allowing you to automatically enrol students in courses based on data in your external db, ldap directory, etc...

The suggestion is nearly always to adopt processes that will protect your upgrade path and maintain integrity of disparate systems... plugins are a much better way to go than the alternative.wink





Good luck,

MC
Ngā whakawākanga toharite: Useful (1)
In reply to Myles Carrick

Re: what happens when a user enrols a course

Martin Dougiamas -
Pikitia o Core developers Pikitia o Documentation writers Pikitia o Moodle HQ Pikitia o Particularly helpful Moodlers Pikitia o Plugin developers Pikitia o Testers
Good answer. I would add that using the API functions is OK too.

This one is particularyl useful for this case:

enrol_into_course($course, $user, $enrol);

(in lib/accesslib.php)
Ngā whakawākanga toharite: -
In reply to Martin Dougiamas

Re: what happens when a user enrols a course

ned moltoya -
How exactly do we use this function? I put together the following:

<?php
require_once('../lib/accesslib.php');
require_once('../lib/dmllib.php');
enrol_into_course($course=84, $USER=22, $enrol='manual');
?>

The obvious goal is to quickly enrol user with id 22 into course with id 84 but to little effect
Ngā whakawākanga toharite: -
In reply to ned moltoya

Re: what happens when a user enrols a course

Martin Dougiamas -
Pikitia o Core developers Pikitia o Documentation writers Pikitia o Moodle HQ Pikitia o Particularly helpful Moodlers Pikitia o Plugin developers Pikitia o Testers
$course and $user are objects, and $USER is already defined as the current user, so your code should look more like this:


require_once('../config.php'); // Includes all the Moodle libraries you need

require_login(); // Makes sure the user is logged in

$course = get_record('course', 'id', 84); // Gets the course object with the given id

if ($course) {
enrol_into_course($course, $USER, 'manual'); // ta da
} else {
print_error('coursenotfound');
}

?>
Ngā whakawākanga toharite: -
In reply to Martin Dougiamas

Re: what happens when a user enrols a course

ned moltoya -
Cool! Tnx

Where should I start for stuff like this, besides your private email? wink
Ngā whakawākanga toharite: -