I would like to get a Group/Grouping ID from Moodle for a customization of the UI of a course. I need to show Resources to specific Groups/Groupings. I’ve already got it set up Moodle. I’ve logged in as different users was able to only access the Resources assigned to that user’s group.
My theme has a custom sidebar menu with links to Pages, Assignments and all other Resources to users for that course. I need to display the correct Resources to a user in the menu using a PHP if/else statement depending on the value of the Group/Grouping ID. I’ve found some documentation on Moodle.com. I came up with this code that breaks my theme.
<?php
// Get the course module id from a post or get request.
$id = required_param('id', PARAM_INT);
// Get the course module.
$cm = get_coursemodule_from_id('forum', $id, 0, false, MUST_EXIST)
// Get the current group id.
$currentgroupingid = groups_get_activity_grouping($cm);
switch($currentgroupingid) {
case "1":
echo "Group 1";
break;
case "2":
echo "Group 2";
break;
case "3":
echo "Group 3";
break;
default:
break;
}?>
This code doesn’t work and I’m not sure why. In the documentation there are example on how to access information about Groups and Groupings. Moodle Group API
In my Moodle Course there are three different Groups. I needed the ability to dynamically change the a href of a link on a webpage resource based on a User’s Group Enrollment Key. This is what I did:
There probably is a better way to do this, but its fine for a Noob like me.