Wednesday, July 7, 2010

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";
}
Post a Comment

Popular Posts