Suppose a teacher logs in for a course, I can programmatically find out the role of the logged in user as teacher, no problem
global $USER;
$context = context_course::instance($COURSE->id);
$roles = get_user_roles($context, $USER->id, false);
$role = key($roles);
$roleid = $roles[$role]->roleid;
Suppose the teacher chooses LOG IN AS a STUDENT, how do I find out the current role of the logged in user based on the logged in user id since it will always show as TEACHER and not STUDENT ?
Any help will be appreciated
Thanks