original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Get the list of ratings for each post. The ratings are returned in an array
  indexed by the post id.
  
  @param stdClass $user The user viewing the ratings.
  @param array $groupedposts List of posts grouped by discussions.
  @return array Sets of ratings indexed by post id.
docstring_tokens: Get the list of ratings for each post . The ratings are returned in an array indexed by the post id .