Get no of enrolled courses of a user

Get no of enrolled courses of a user

autor Siddharth Patel -
Počet odpovědí: 5

Hello Moodlers!

I am trying to make a list in which the logged user will get the list and number of enrolled courses by them, as they are getting in the Dashboard.

I tried to find for function or tried to get from the database but could not get the exact solution for the same.

Any suggestion?

Moodle version: 3.8

Thanks in Advance

Průměr hodnocení: -
V odpovědi na Siddharth Patel

Re: Get no of enrolled courses of a user

autor praveen kota -

Hi, @siddharth 

I don't know exactly but I'm trying to help you with this

User Enrolled courses are available in their profile they can see directly from their profile. 

why do you want to make this? and I think you can do using a custom report  (add a custom report plugin) users and a list of courses they enrolled in.

V odpovědi na praveen kota

Re: Get no of enrolled courses of a user

autor Siddharth Patel -
Thank you for the reply.

Here I have created a new page. In which if the user is having courses in progress then they can see them. But if the user has not started any of the course so far then is the banner for introduction that should be seen. I have been trying to make that possible from database condition or other related functions, but could not find them.
V odpovědi na Siddharth Patel

Re: Get no of enrolled courses of a user

autor Renaat Debleu -
Obrázek: Core developers Obrázek: Particularly helpful Moodlers Obrázek: Plugin developers
Guess where you can find information about users enrolled in a course? The file lib/enrollib.php is a good start point:

The enrol_get_all_users_courses($userid, $onlyactive = false, $fields = null, $sort = null) function returns the list of courses a user is enrolled into without performing any capability checks.
The enrol_get_users_courses($userid, $onlyactive = false, $fields = null, $sort = null) function returns the list of courses user is enrolled into with capability checks.