protected static function export_grading_instances(\context $context, array $subcontext, int $definitionid, int $userid = 0) {
        global $DB;

        $params = ['definitionid' => $definitionid];
        if (!empty($userid)) {
            $params['raterid'] = $userid;
        }
        $instances = $DB->get_recordset('grading_instances', $params);
        $instancedata = [];
        foreach ($instances as $instance) {
            // TODO: Get the status name (instead of the ID).
            $tmpdata = [
                'rawgrade' => $instance->rawgrade,
                'status' => $instance->status,
                'feedback' => $instance->feedback,
                'feedbackformat' => $instance->feedbackformat,
                'timemodified' => transform::datetime($instance->timemodified),
            ];
            $instancedata[] = (object) $tmpdata;
        }
        $instances->close();

        if (!empty($instancedata)) {
            $data = (object) [
                'instances' => $instancedata,
            ];

            writer::with_context($context)->export_related_data($subcontext, 'gradinginstances', $data);
        }
    }