protected static function validate_course($courseorid, $throwexception = true) {
        $course = $courseorid;
        if (!is_object($course)) {
            $course = get_course($course);
        }

        $coursecontext = context_course::instance($course->id);
        if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
            if ($throwexception) {
                throw new require_login_exception('Course is hidden');
            } else {
                return false;
            }
        }

        return true;
    }
protected static function validate_course($courseorid, $throwexception = true) {
        $course = $courseorid;
        if (!is_object($course)) {
            $course = get_course($course);
        }

        $coursecontext = context_course::instance($course->id);
        if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
            if ($throwexception) {
                throw new require_login_exception('Course is hidden');
            } else {
                return false;
            }
        }

        return true;
    }
protected static function validate_course ( $ courseorid , $ throwexception = true ) { $ course = $ courseorid ; if ( ! is_object ( $ course ) ) { $ course = get_course ( $ course ) ; } $ coursecontext = context_course :: instance ( $ course -> id ) ; if ( ! $ course -> visible and ! has_capability ( 'moodle/course:viewhiddencourses' , $ coursecontext ) ) { if ( $ throwexception ) { throw new require_login_exception ( 'Course is hidden' ) ; } else { return false ; } } return true ; }
Validate if current user have acces to the course if hidden.

@param mixed $courseorid The course or it ID.
@param bool $throwexception Throw an exception or not.
@return bool
Validate if current user have acces to the course if hidden .