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";
}
$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:
very tnx!
Thank
Thanks
Nice!, thanks for taking the time to publish this article.
Ok, but it doesn't work on moodle 2.2 because legacy.
Any solution to do this without legacy?
This doesn't work for Moodle 2.3. Do you know solution?
Post a Comment