Question about roles system.

Question about roles system.

by victor V -
Number of replies: 2
Hello .
I still have some problems with the role system , I wanted to check if a user is a teacher in any group of a course, but I dont seem to make it work.
this is what I have so far.

$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
if(has_capability('moodle/legacy:teacher', $context,$user->id)){
echo "Is theacer";
}

it works but it only shows as teachers the one that are in the current group but not on all the groups in the course, I am using a foreach to go through the users and check which has teacher role in any group.

Hope you can help me
Average of ratings: -
In reply to victor V

Re: Question about roles system.

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Victor,

Sorry I can't answer your question, but I'm going to move your discussion to the roles and capabilities forum, where hopefully someone will be able to help.
In reply to victor V

Re: Question about roles system.

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Why do you want to know if a user is a teacher? What are you going to do, or not do, based on that knowledge?

has_capability does not know anything about groups, I suspect the group restriction is coming from elsewhere in the code. Where is $user coming from.