是否可以在Moodle中找到登录用户的组ID或名称?

时间:2012-11-28 18:07:55

标签: moodle

是否可以在Moodle 1.9中找到已登录用户的组/分组ID?

1 个答案:

答案 0 :(得分:0)

在我的Moodle课程中,有三个不同的小组。我需要能够根据用户的组注册密钥动态更改网页资源上链接的href。这就是我所做的:


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

可能有一种更好的方法可以做到这一点,但对于像我这样的Noob来说这很好。