protected static function export_authored_policies(\stdClass $user) {
        global $DB;

        // Authored policies are exported against the system.
        $context = \context_system::instance();
        $basecontext = [
            get_string('policydocuments', 'tool_policy'),
        ];

        $sql = "SELECT v.id,
                       v.name,
                       v.revision,
                       v.summary,
                       v.content,
                       v.archived,
                       v.usermodified,
                       v.timecreated,
                       v.timemodified,
                       p.currentversionid
                  FROM {tool_policy_versions} v
                  JOIN {tool_policy} p ON p.id = v.policyid
                 WHERE v.usermodified = :userid";
        $versions = $DB->get_recordset_sql($sql, ['userid' => $user->id]);
        foreach ($versions as $version) {
            $subcontext = array_merge($basecontext, [get_string('policynamedversion', 'tool_policy', $version)]);

            $versioncontent = (object) [
                'name' => $version->name,
                'revision' => $version->revision,
                'summary' => writer::with_context($context)->rewrite_pluginfile_urls(
                    $subcontext,
                    'tool_policy',
                    'policydocumentsummary',
                    $version->id,
                    $version->summary
                ),
                'content' => writer::with_context($context)->rewrite_pluginfile_urls(
                    $subcontext,
                    'tool_policy',
                    'policydocumentcontent',
                    $version->id,
                    $version->content
                ),
                'isactive' => transform::yesno($version->id == $version->currentversionid),
                'isarchived' => transform::yesno($version->archived),
                'createdbyme' => transform::yesno($version->usermodified == $user->id),
                'timecreated' => transform::datetime($version->timecreated),
                'timemodified' => transform::datetime($version->timemodified),
            ];
            writer::with_context($context)
                ->export_data($subcontext, $versioncontent)
                ->export_area_files($subcontext, 'tool_policy', 'policydocumentsummary', $version->id)
                ->export_area_files($subcontext, 'tool_policy', 'policydocumentcontent', $version->id);
        }
        $versions->close();
    }