public function check_access($id) {
        global $DB;

        // Check we can get the section and the course modinfo.
        $sectionrec = $DB->get_record('course_sections', ['id' => $id], '*', IGNORE_MISSING);
        if (!$sectionrec) {
            return \core_search\manager::ACCESS_DELETED;
        }
        try {
            $modinfo = get_fast_modinfo($sectionrec->course);
        } catch (\moodle_exception $e) {
            return \core_search\manager::ACCESS_DELETED;
        }
        $section = $modinfo->get_section_info($sectionrec->section, IGNORE_MISSING);
        if (!$section) {
            return \core_search\manager::ACCESS_DELETED;
        }

        // Check access to course and that the section is visible to current user.
        if (can_access_course($modinfo->get_course()) && $section->uservisible) {
            return \core_search\manager::ACCESS_GRANTED;
        }

        return \core_search\manager::ACCESS_DENIED;
    }