Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8942855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:37:36+00:00 2026-06-15T11:37:36+00:00

I would like to get a Group/Grouping ID from Moodle for a customization of

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:37:37+00:00Added an answer on June 15, 2026 at 11:37 am

    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:


    <div class="enrolment-key" style="display:none;">
    <?php
        // Grab current User's group from Database By ID
        $sqlGROUPMEMBERS = "SELECT * FROM mdl_groups_members WHERE userid='$USER->id'";
    
        // Put Query in new Varible
        $resultGROUPMEMBERS = mysql_query($sqlGROUPMEMBERS);
    
        // While $row = group id of user
        while($row = mysql_fetch_array($resultGROUPMEMBERS)){
            $groupID = $row["groupid"];
        }
    
        // Grab Enrolment Key by the Group ID
        $sqlGROUP = "SELECT * FROM mdl_groups WHERE id=$groupID";
    
        // Put Query in new Varible
        $resultENROLMENTKEY = mysql_query($sqlGROUP);
    
        // While $row = group enrolment key for that user
        while($row = mysql_fetch_array($resultENROLMENTKEY)){
            echo $row["enrolmentkey"];
        }
    ?>
    </div>
    <script>
    $(document).ready(function(){
    var baseURL = "https://www.surveymonkey.com/s/";
    var endURL = $('.enrolment-key').html();
    
    $(".survey-link").attr("href", baseURL + endURL);
     });
     </script>
    <a class="survey-link">Link</a>
    

    There probably is a better way to do this, but its fine for a Noob like me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get View instance that is used to display specific Preference
I would like to get a help from you all. The below is the
Would like to get the following as a result from the table structure below
I would like to get numbers of comments for each posts using mysql. I
I would like to get to know how to redirect output of some program
I would like to get the generic information ( Counter class) of my CounterPersistence
I would like to get rid of the close/X button on the top right
I would like to get started developing games with Flixel, but im on a
I would like to get the weighted_median of an unsorted, variable length, eigen c++
I would like to get the dimensions (coordinates) for all the HTML elements of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.