public static function is_user_gradable_in_course($courseid, $userid) {
        global $CFG;

        $gradableuser = false;
        $coursecontext = \context_course::instance($courseid);
        if (is_enrolled($coursecontext, $userid, '', false)) {
            $roles = get_user_roles($coursecontext, $userid);
            $gradebookroles = explode(',', $CFG->gradebookroles);
            foreach ($roles as $role) {
                foreach ($gradebookroles as $gradebookrole) {
                    if ($role->roleid = $gradebookrole) {
                        $gradableuser = true;
                    }
                }
            }
        }

        return $gradableuser;
    }
public static function is_user_gradable_in_course($courseid, $userid) {
        global $CFG;

        $gradableuser = false;
        $coursecontext = \context_course::instance($courseid);
        if (is_enrolled($coursecontext, $userid, '', false)) {
            $roles = get_user_roles($coursecontext, $userid);
            $gradebookroles = explode(',', $CFG->gradebookroles);
            foreach ($roles as $role) {
                foreach ($gradebookroles as $gradebookrole) {
                    if ($role->roleid = $gradebookrole) {
                        $gradableuser = true;
                    }
                }
            }
        }

        return $gradableuser;
    }
public static function is_user_gradable_in_course ( $ courseid , $ userid ) { global $ CFG ; $ gradableuser = false ; $ coursecontext = \ context_course :: instance ( $ courseid ) ; if ( is_enrolled ( $ coursecontext , $ userid , '' , false ) ) { $ roles = get_user_roles ( $ coursecontext , $ userid ) ; $ gradebookroles = explode ( ',' , $ CFG -> gradebookroles ) ; foreach ( $ roles as $ role ) { foreach ( $ gradebookroles as $ gradebookrole ) { if ( $ role -> roleid = $ gradebookrole ) { $ gradableuser = true ; } } } } return $ gradableuser ; }
Check if a user can be graded in a course

@param int $courseid The course
@param int $userid The user
@return bool
Check if a user can be graded in a course