public static function check_access($systemcontext, $context, $personalcontext, $course, $userid) {
        global $USER;

        $access = false;
        if (has_capability('moodle/grade:viewall', $systemcontext)) {
            // Ok - can view all course grades.
            $access = true;

        } else if (has_capability('moodle/grade:viewall', $context)) {
            // Ok - can view any grades in context.
            $access = true;

        } else if ($userid == $USER->id and ((has_capability('moodle/grade:view', $context) and $course->showgrades)
                || $course->id == SITEID)) {
            // Ok - can view own course grades.
            $access = true;

        } else if (has_capability('moodle/grade:viewall', $personalcontext) and $course->showgrades) {
            // Ok - can view grades of this user - parent most probably.
            $access = true;
        } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and $course->showgrades) {
            // Ok - can view grades of this user - parent most probably.
            $access = true;
        }
        return $access;
    }
public static function check_access($systemcontext, $context, $personalcontext, $course, $userid) {
        global $USER;

        $access = false;
        if (has_capability('moodle/grade:viewall', $systemcontext)) {
            // Ok - can view all course grades.
            $access = true;

        } else if (has_capability('moodle/grade:viewall', $context)) {
            // Ok - can view any grades in context.
            $access = true;

        } else if ($userid == $USER->id and ((has_capability('moodle/grade:view', $context) and $course->showgrades)
                || $course->id == SITEID)) {
            // Ok - can view own course grades.
            $access = true;

        } else if (has_capability('moodle/grade:viewall', $personalcontext) and $course->showgrades) {
            // Ok - can view grades of this user - parent most probably.
            $access = true;
        } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and $course->showgrades) {
            // Ok - can view grades of this user - parent most probably.
            $access = true;
        }
        return $access;
    }
public static function check_access ( $ systemcontext , $ context , $ personalcontext , $ course , $ userid ) { global $ USER ; $ access = false ; if ( has_capability ( 'moodle/grade:viewall' , $ systemcontext ) ) { // Ok - can view all course grades. $ access = true ; } else if ( has_capability ( 'moodle/grade:viewall' , $ context ) ) { // Ok - can view any grades in context. $ access = true ; } else if ( $ userid == $ USER -> id and ( ( has_capability ( 'moodle/grade:view' , $ context ) and $ course -> showgrades ) || $ course -> id == SITEID ) ) { // Ok - can view own course grades. $ access = true ; } else if ( has_capability ( 'moodle/grade:viewall' , $ personalcontext ) and $ course -> showgrades ) { // Ok - can view grades of this user - parent most probably. $ access = true ; } else if ( has_capability ( 'moodle/user:viewuseractivitiesreport' , $ personalcontext ) and $ course -> showgrades ) { // Ok - can view grades of this user - parent most probably. $ access = true ; } return $ access ; }
Check if the user can access the report.

@param  stdClass $systemcontext   system context
@param  stdClass $context         course context
@param  stdClass $personalcontext personal context
@param  stdClass $course          course object
@param  int $userid               userid
@return bool true if the user can access the report
@since  Moodle 3.2
Check if the user can access the report .