public static function get_default_completion($course, $module, $flatten = true) {
        global $DB, $CFG;
        if ($data = $DB->get_record('course_completion_defaults', ['course' => $course->id, 'module' => $module->id],
            'completion, completionview, completionexpected, completionusegrade, customrules')) {
            if ($data->customrules && ($customrules = @json_decode($data->customrules, true))) {
                if ($flatten) {
                    foreach ($customrules as $key => $value) {
                        $data->$key = $value;
                    }
                } else {
                    $data->customdata['customcompletionrules'] = $customrules;
                }
            }
            unset($data->customrules);
        } else {
            $data = new stdClass();
            $data->completion = COMPLETION_TRACKING_NONE;
            if ($CFG->completiondefault) {
                $completion = new \completion_info(get_fast_modinfo($course->id)->get_course());
                if ($completion->is_enabled() && plugin_supports('mod', $module->name, FEATURE_MODEDIT_DEFAULT_COMPLETION, true)) {
                    $data->completion = COMPLETION_TRACKING_MANUAL;
                    $data->completionview = 1;
                }
            }
        }
        return $data;
    }