private function get_ratings_from_posts(stdClass $user, array $groupedposts) {
        $ratingsbypostid = [];
        $postsdatamapper = $this->legacydatamapperfactory->get_post_data_mapper();
        $postsbyforum = array_reduce($groupedposts, function($carry, $grouping) {
            ['forum' => $forum, 'posts' => $posts] = $grouping;

            $forumid = $forum->get_id();
            if (!isset($carry[$forumid])) {
                $carry[$forumid] = [
                    'forum' => $forum,
                    'posts' => []
                ];
            }

            $carry[$forumid]['posts'] = array_merge($carry[$forumid]['posts'], $posts);
            return $carry;
        }, []);

        foreach ($postsbyforum as $grouping) {
            ['forum' => $forum, 'posts' => $posts] = $grouping;

            if (!$forum->has_rating_aggregate()) {
                continue;
            }

            $items = $postsdatamapper->to_legacy_objects($posts);
            $ratingoptions = (object) [
                'context' => $forum->get_context(),
                'component' => 'mod_forum',
                'ratingarea' => 'post',
                'items' => $items,
                'aggregate' => $forum->get_rating_aggregate(),
                'scaleid' => $forum->get_scale(),
                'userid' => $user->id,
                'assesstimestart' => $forum->get_assess_time_start(),
                'assesstimefinish' => $forum->get_assess_time_finish()
            ];

            $rm = $this->ratingmanager;
            $items = $rm->get_ratings($ratingoptions);

            foreach ($items as $item) {
                $ratingsbypostid[$item->id] = empty($item->rating) ? null : $item->rating;
            }
        }

        return $ratingsbypostid;
    }