Get no of enrolled courses of a user

Get no of enrolled courses of a user

par Siddharth Patel,
Nombre de réponses : 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

Moyenne des évaluations  -
En réponse à Siddharth Patel

Re: Get no of enrolled courses of a user

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

En réponse à praveen kota

Re: Get no of enrolled courses of a user

par 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.
En réponse à Siddharth Patel

Re: Get no of enrolled courses of a user

par Renaat Debleu,
Avatar Core developers Avatar Particularly helpful Moodlers Avatar 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.
Moyenne des évaluations Useful (2)
En réponse à Renaat Debleu

Re: Get no of enrolled courses of a user

par Siddharth Patel,
Thank you so much Renaat!!
That was exactly I was looking for and achieved what was required. sourire