Pages

Thursday, May 5, 2011

Getting roles of logged in users in Moodle LMS

global $COURSE, $USER;

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

if (has_capability('moodle/legacy:student', $context, $USER->id, false) ) {
echo "I'm a student";
}
if (has_capability('moodle/legacy:teacher', $context, $USER->id, false) ) {
echo "I'm an Assistant Teacher";
}
if (has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)) {
echo "I'm  a teacher";
}
if (has_capability('moodle/legacy:admin', $context, $USER->id, false)) {
echo "I'm Admin";
}



0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.