protected static function transform_grade(grade_grade $gg, context $context, bool $ishistory) {
        $gi = $gg->load_grade_item();
        $timemodified = $gg->timemodified ? transform::datetime($gg->timemodified) : null;
        $timecreated = $gg->timecreated ? transform::datetime($gg->timecreated) : $timemodified; // When null we use timemodified.

        $filearea = $ishistory ? GRADE_HISTORY_FEEDBACK_FILEAREA : GRADE_FEEDBACK_FILEAREA;
        $itemid = $ishistory ? $gg->historyid : $gg->id;
        $subpath = $ishistory ? get_string('feedbackhistoryfiles', 'core_grades') : get_string('feedbackfiles', 'core_grades');

        $pathtofiles = [
            get_string('grades', 'core_grades'),
            $subpath
        ];
        $gg->feedback = writer::with_context($gg->get_context())->rewrite_pluginfile_urls(
            $pathtofiles,
            GRADE_FILE_COMPONENT,
            $filearea,
            $itemid,
            $gg->feedback
        );

        return [
            'gradeobject' => $gg,
            'item' => $gi->get_name(),
            'grade' => $gg->finalgrade,
            'grade_formatted' => grade_format_gradevalue($gg->finalgrade, $gi),
            'feedback' => format_text($gg->feedback, $gg->feedbackformat, ['context' => $context]),
            'information' => format_text($gg->information, $gg->informationformat, ['context' => $context]),
            'timecreated' => $timecreated,
            'timemodified' => $timemodified,
        ];
    }