Databases: Some database queries about students and courses
- list of courses to which the student is registered
- list of courses avaliable to student
- list of courses that student of certan class should participate
I don't need whole SQL queries just some tips which tables and fileds to look and how they connect.
Many thanks to you all.
Re: Databases: Some database queries about students and courses
This will get you students and the (comma separated) courses they've been added to (I think that corresponds to the 1st *or* 2nd of your queries, it depends on the authentication method / how you add students (I think)):
SELECT u.id, GROUP_CONCAT( co.fullname )
FROM mdl2_user u
JOIN mdl2_role_assignments ra ON u.id = ra.userid
JOIN mdl2_role r ON r.id = ra.roleid
JOIN mdl2_context c ON ra.contextid = c.id
JOIN mdl2_course co ON c.instanceid = co.id
WHERE r.id = 5
GROUP BY u.id
ORDER BY u.id
(assuming 5 is the id for "student" in your role table).
Odg: Re: Some database queries about students and courses
I am using version 1.9 and i thik the only diference in this case is in table names( names are without number 2 ).
What about third querie ? Can i determine to which course and grade student belong and what are the lectures he should/could participate in ?
Explanation for easier undestanding what i mean:
we have two courses, each having a four grades/years(i don't know what is the right name).
For each course and year we have different set of lectures. Can i get the list of this lectures for certain student ?
Best regards, Boštjan
Odg: Re: Some database queries about students and courses
Can you please tell a bit more about your query ?
What is the MDL_CONTEXT table and its filed instanceid ?
I don't get it how are MDL_COURSE, MDL_CONTEXT, MDL_ROLE and MDL_ROLE_ASSIGMENTS connected.
Best regards, Bostjan.
Re: Odg: Re: Some database queries about students and courses
Course: id < -> Context:instanceid (a course has a context)
Context:id < -> Role_assignments:contextid
for each user who has a role (student, teacher) in that context (course), there is a record in Role_assignments.
This record includes a userid and a roleid. userid maps to user:id. Roleid maps to role:id.
See also http://docs.moodle.org/en/Development:Database_schema_introduction
Re: Odg: Re: Some database queries about students and courses
Re: Odg: Re: Some database queries about students and courses
Odg: Re: Odg: Re: Some database queries about students and courses
If Context:contextlevel = 50 then
Context:id < -> Role_assignments:contextid
Context:instanceid < - > Course:id
But what Context:id and Context:instanceid menas when Context:contextlevel is 10,20,30,40 and 80 ?
Re: Odg: Re: Odg: Re: Some database queries about students and courses
context:id < -> role_assignments:contextid
There is only one context with level 10, the system context.
level 20 does not exist.
level 30 is user context. context:instanceid < - > user:id
level 40 is course category context. context:instanceid < - > course_categories:id
Level 70 is module context. context:instanceid < - > course_modules:id
Level 80 is block context. context:instanceid < - > block_instances:id
Re: Odg: Re: Odg: Re: Some database queries about students and courses
Thanks,this really helps.Today,I'm trying to use the moodle_role_assign web-service function and need to know what context level is.Does this mean every user record has its context record with level:30 in this table?Or is there any other mechanism?
Re: Odg: Re: Odg: Re: Some database queries about students and courses
Correct.
The context levels are set up as constants in /lib/accesslib.php, because they can't be added to or changed by the user, and for reasons explained here.
There's no way of knowing where they come from, though, when you are following things through in the database and find yourself staring at the contextlevel field.