public static function create_template(stdClass $record) {
        static::require_enabled();
        $template = new template(0, $record);

        // First we do a permissions check.
        if (!$template->can_manage()) {
            throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
                'nopermissions', '');
        }

        // OK - all set.
        $template = $template->create();

        // Trigger a template created event.
        \core\event\competency_template_created::create_from_template($template)->trigger();

        return $template;
    }