public static function update_course_competency_settings($courseid, $settings) {
        static::require_enabled();

        $settings = (object) $settings;

        // Get all the valid settings.
        $pushratingstouserplans = isset($settings->pushratingstouserplans) ? $settings->pushratingstouserplans : false;

        // First we do a permissions check.
        if (!course_competency_settings::can_manage_course($courseid)) {
            $context = context_course::instance($courseid);
            throw new required_capability_exception($context, 'moodle/competency:coursecompetencyconfigure', 'nopermissions', '');
        }

        $exists = course_competency_settings::get_record(array('courseid' => $courseid));

        // Now update or insert.
        if ($exists) {
            $settings = $exists;
            $settings->set('pushratingstouserplans', $pushratingstouserplans);
            return $settings->update();
        } else {
            $data = (object) array('courseid' => $courseid, 'pushratingstouserplans' => $pushratingstouserplans);
            $settings = new course_competency_settings(0, $data);
            $result = $settings->create();
            return !empty($result);
        }
    }