public static function get_subject_scope(\context $context) {

        if ($contextcourse = $context->get_course_context(false)) {
            // Below course level we look at module or block level roles + course-assigned roles.
            $courseroles = get_roles_used_in_context($contextcourse, false);
            $roles = $courseroles + get_roles_used_in_context($context, false);
        } else {
            // We list category + system for others (we don't work with user instances so no need to work about them).
            $roles = get_roles_used_in_context($context);
        }

        return array_map(function($role) {
            if ($role->name) {
                return $role->name;
            } else {
                return $role->shortname;
            }
        }, $roles);
    }
public static function get_subject_scope(\context $context) {

        if ($contextcourse = $context->get_course_context(false)) {
            // Below course level we look at module or block level roles + course-assigned roles.
            $courseroles = get_roles_used_in_context($contextcourse, false);
            $roles = $courseroles + get_roles_used_in_context($context, false);
        } else {
            // We list category + system for others (we don't work with user instances so no need to work about them).
            $roles = get_roles_used_in_context($context);
        }

        return array_map(function($role) {
            if ($role->name) {
                return $role->name;
            } else {
                return $role->shortname;
            }
        }, $roles);
    }
public static function get_subject_scope ( \ context $ context ) { if ( $ contextcourse = $ context -> get_course_context ( false ) ) { // Below course level we look at module or block level roles + course-assigned roles. $ courseroles = get_roles_used_in_context ( $ contextcourse , false ) ; $ roles = $ courseroles + get_roles_used_in_context ( $ context , false ) ; } else { // We list category + system for others (we don't work with user instances so no need to work about them). $ roles = get_roles_used_in_context ( $ context ) ; } return array_map ( function ( $ role ) { if ( $ role -> name ) { return $ role -> name ; } else { return $ role -> shortname ; } } , $ roles ) ; }
Returns the roles assigned to the provided level.

Important to note that it returns course-level assigned roles
if the provided context level is below course.

@param \context $context
@return array
Returns the roles assigned to the provided level .