Databases: Where did mdl_user_students go?

Databases: Where did mdl_user_students go?

by Deleted user -
Number of replies: 14

I have to write some custom code to create accounts and enroll students. In Moodle 1.6, the mdl_user table contained all the users and the mdl_user_students table contained a list of courses that each student belongs too. In Moodle 1.9 I noticed that there is no longer a mdl_user_students table. I was looking thru some of the other tables, but I can't figure out how a student is enrolled in a course in the database. I'm assuming it has something to do with roles, but I can't decipher how it works.

QUESTION #1 - Which table(s) contains the list of courses that a student is enrolled in Moodle 1.9?

QUESTION #2 - Are there any available functions within Moodle that will create new accounts and enroll students in a course that I can call without making a direct write to the database?

Thanks

P.S.- I did search thru the forums, but could not find an answer to my questions, probably due to the fact that I did not know/use the proper terminology.

Average of ratings: -
In reply to Deleted user

Re: Databases: Where did mdl_user_students go?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well, there's no such thing as students (sort of) any more. There's roles. Roles are just a collection of permissions and there's one created for you called 'student' but other than that there's nothing special about students anymore. What you are actually asking is how to create a user and then assign them to a particular role (most likely student) in a course.

Before we go any further, are you *sure* that database authentication and database enrolment won't do this for you?
In reply to Howard Miller

Re: Databases: Where did mdl_user_students go?

by Deleted user -

Thanks for the reply Howard...

Unless I misunderstand how database authentication and database enrolment work, then no, they won't do for this.

What I need to do is this:

When somebody purchases a class thru our e-commerce shopping cart, upon approval of their credit card payment, I need IMMEDIATE account creation (if it's a new account) and an IMMEDIATE enrolment in the purchased course. Then, when they login for the first time, their account is already created and they are alreay enroled in the course.

Thanks

In reply to Deleted user

Re: Databases: Where did mdl_user_students go?

by Deleted user -

Hi again Howard...

I did go back and look again at these other methods of authentication and enrolment. I played around with External Database as an Authentication method, and it appears that it will do EXACTLY what I need it to do. I simply need to enter the appropriate info into an external database when the purchase is approved, and when the student logs in for the first time, they are automatically and seamlessly created right away!

I have not had a chance to play with the External Database Enrolment yet, but I imagine that it will be just as simple? I assumne I just enter the appropriate info in the external database and when the student logs in for the first time, they will be automatically enroled in the appropriate course.

Thanks Howard for pointing me in the right direction... I think I initally looked at all the different options (IMAP, LDAP, PAM, RADIUS, etc) and was overwhelmed by what option I needed!! I thought it would be easier to just custom write my own code!! But this will certainly save a lot of time, AND it will always be compatible with future versions of Moodle without having to worry about re-writing code everytime I upgrade!

One more question though... what happens if the external database contains a field that needs to be unique (email address or username) that is already being used by another student in the Moodle database? Will it simply not create the new account?

Okay, thanks again!

In reply to Deleted user

Re: Databases: Where did mdl_user_students go?

by Simon MELIX -
Hi,

Maybe this is what you want...?
I had the same question in the french community, that helped me a lot...
DB Shema.

I hope this will help you

Regards,
Simon
In reply to Deleted user

Re: Databases: Where did mdl_user_students go?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes, Database Enrolment will do what you want. I imagine that your ecommerce application will populate the database. When they login their enrolments are checked and they are automagically enrolled into any and all courses as indicated by the database.

Job done smile
In reply to Howard Miller

Re: Databases: Where did mdl_user_students go?

by Deleted user -

Okay, I've playing around with External DB Authentication, and I've come across the following problem with using it... it won't let users change their own passwords!

Is there a way to allow users to change their password from within Moodle AND have it update the External DB as well? It seems that it should be possible, since it can update all the other fields from the user profile in the external db, but I can't find an option for it!

In reply to Deleted user

Re: Databases: Where did mdl_user_students go?

by Deleted user -

After reviewing several methods of authenrication and enrolment, I find that none work exactly as I need them to, and will have to custom write some code. Therefore I have to go back and ask the very first questions again, since they never actually got answered because I tried some other things. Here they are:

QUESTION #1 - Which table(s) contains the list of courses that a student is enrolled in Moodle 1.9 (it was mdl_user_students in 1.6)?

QUESTION #2 - Are there any available functions within Moodle that will create new accounts and/or enroll students in a course that I can call without making a direct write to the database?

Thanks again

In reply to Deleted user

Re: Databases: Where did mdl_user_students go?

by John Maher -
In the interest (my interest, of course) of encouraging anyone who knows to answer your questions, I too am looking for the answer to QUESTION #1 (although we use version 1.8).

My situation is different, and sad, because we currently are forced to manually load accounts. But I want to move everyone who is in a particular course to a different course. So, if anyone can help with Jeff's questions, I too would appreciate it.

Thanks.

John
In reply to John Maher

Re: Databases: Where did mdl_user_students go?

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
It's a combination of mdl_role, mdl_context and mdl_role_assignments (and of course, mdl_user and mdl_course).

Saludos. Iñaki.
In reply to Deleted user

Re: Databases: Where did mdl_user_students go?

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Moodle is a "slave" to the external database, in read-only mode (good for security).

The solution is to specify an external URL where users will be sent to change their passwords, look for "Password-change URL" on the database auth page.

In your case this would be some little script that updates the external database (and then it will be used on their next login).
In reply to Martin Dougiamas

Re: Databases: Where did mdl_user_students go?

by Deleted user -

Thanks Martin,

Interesting suggestion, except I have a requirement that everything be accessible/changeable from within Moodle, meaing that admins need to be able to change username/passwords from Moodle. Although the external password-url would allow students to change their own password, it would not allow admins to do it because Edit Profile will not update their password on the external system.

In reply to Deleted user

Re: Databases: Where did mdl_user_students go?

by Deleted user -

I guess what I'm really looking for might be called an 'api'... functions that I can call that will take care of all the details, without me having to do a direct db write.

I found these functions:

create_user_record() in moodle/lib/moodlelib.php - This will create a new user, but only adds the username and password. I can't find another function that updates the other fields (firstname, lastname, country, etc). Any suggestions on where to look?

enrol_into_course() in moodle/lib/accesslib.php - This looks like it will enrol a student in a course. I'm assuming that $course->id is the course id number of the course (as opposed to the shortname).

Is there any problem with using these functions?

In reply to Deleted user

Re: Databases: Where did mdl_user_students go?

by Peter DeBruyn -
I'm having the same sort of issues Jeff was having. Here is the query i used with 1.5.4 to enrol a user into a course from a custom registration script I wrote (I have a long questionnaire they have to fill out and I have to make sure they are not enrolled in a course on the site already): insert into mdl_user_students (userid,course,time,enrol) values ('".$reguserid."','".$regcourseid."','".$currenttime."','".internal."')

I am wondering if I can just insert into mdl_role_assignments the way I did in mdl_user_students? If so, I wondering how to form a correct insert because I don't understand all of the fields in the assignment table.

The post above mentions a function, enrol_into_course(), I'm new to php and wondering how I would go about calling that function from my custom script? Is it as simple as include the accesslib.php file?