2012-11-28 50 views
0

我想從Moodle獲取羣組/羣ID以定製課程的用戶界面。我需要向特定的羣組/分組顯示資源。我已經設置了Moodle。我已登錄,因爲不同的用戶只能訪問分配給該用戶組的資源。如何從Moodle中獲取羣組/羣ID 1.9

我的主題有一個自定義邊欄菜單,其中包含指向該用戶的Pages,Assignments和所有其他資源的鏈接。我需要使用PHP if/else語句在菜單中向用戶顯示正確的資源,具體取決於Group/Grouping ID的值。我在Moodle.com上找到了一些文檔。我想出了這個破壞我主題的代碼。

<?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; 
     }?> 

此代碼不起作用,我不知道爲什麼。在文檔中有關於如何訪問關於組和分組的信息的例子。 Moodle Group API

回答

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> 

有可能是一個更好的方式來做到這一點,但它對於像我這樣的菜鳥罰款。