$course_id = 123; $context = context_course::instance($course_id);
$course_id = 123; $context = context_course::instance($course_id); if ($USER->has_capability('moodle/course:view', $context)) { // user has access to view course content } else { // user does not have access to view course content }Package Library: Moodle (open-source LMS platform)