Get current user group inside course in Moodle

63 Views Asked by At

In Moodle, I have some courses where the users are assigned to groups. I need to make the user group info in the course to be available via JavaScript, so that I can access the group info and do stuff like show and hide content based on the user group.

For example, suppose a course has groups and each group is a country. When a user enters the course, the map of the country he is assigned for will be shown in the course HTML content area. To achieve that, I need to get his course info through javascript and show the correct map.

I have access as admin to Moodle administration, I have access to Moodle files and database. I'm a PHP and JavaScript developer. I'm not a Moodle expert but I have already created some custom course content using HTML + JS + CSS.

I just need to know how to expose the user group via javascript in a Moodle course.

I have read some Moodle documentation and searched the internet, but I couldn't find much clean information on how to do that.

To be more clear, where do I add PHP code in Moodle to achieve that and avoid losing the code in case I update Moodle version? Do I need to create a plugin? Or just add some PHP file somewhere?

0

There are 0 best solutions below