Get no of enrolled courses of a user

Get no of enrolled courses of a user

ni Siddharth Patel -
Number of replies: 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

Average of ratings: -
In reply to Siddharth Patel

Re: Get no of enrolled courses of a user

ni 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.

In reply to praveen kota

Re: Get no of enrolled courses of a user

ni 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.
In reply to Siddharth Patel

Re: Get no of enrolled courses of a user

ni Renaat Debleu -
Larawan ng Core developers Larawan ng Particularly helpful Moodlers Larawan ng 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.