2017-05-29 88 views

回答

0

你可以使用

$user_object = get_record('user', 'id', $USER->id);

爲了檢查用戶是否有特定功能的用戶記錄,您可以使用get_context_instance功能。

global $COURSE, $USER; 

$context = get_context_instance(CONTEXT_COURSE,$COURSE->id); 

if (has_capability('moodle/legacy:student', $context, $USER->id, false)) { 
echo "is Student<br/>"; 
} 
if (has_capability('moodle/legacy:teacher', $context, $USER->id, false)) { 
echo "is Assitent Teacher<br/>"; 
} 
if (has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)) { 
echo "is Teacher<br/>"; 
} 
if (has_capability('moodle/legacy:admin', $context, $USER->id, false)) { 
echo "is ADMIN<br/>"; 
} 
0
$var="SELECT * FROM `mdl_role` as er,`mdl_role_assignments` as era WHERE era.roleid=er.id && userid=$USER->id"; 
$data = mysql_query($var); 
$rec = mysql_fetch_array($data); 
echo $rec['shortname']."<br />"; 

我加入這兩個表,並得到了結果。