find user role

find user role

by jigisha variya -
Number of replies: 0

i am working on moodle 2.0

how do i find user role in system ?

i tried below code: but it gives me error.

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

Please help me..

Average of ratings: -