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

6 comments:

Anonymous said...

very tnx!

Anonymous said...

Thank

Anonymous said...

Thanks

Pablo Borbón said...

Nice!, thanks for taking the time to publish this article.

MOL said...

Ok, but it doesn't work on moodle 2.2 because legacy.
Any solution to do this without legacy?

Unknown said...

This doesn't work for Moodle 2.3. Do you know solution?

Popular Posts