original_string: private function get_author_groups_from_posts(array $posts, $forum) : array {
          $course = $forum->get_course_record();
          $coursemodule = $forum->get_course_module_record();
          $authorids = array_reduce($posts, function($carry, $post) {
              $carry[$post->get_author_id()] = true;
              return $carry;
          }, []);
          $authorgroups = groups_get_all_groups($course->id, array_keys($authorids), $coursemodule->groupingid,
                  'g.*, gm.id, gm.groupid, gm.userid');
  
          $authorgroups = array_reduce($authorgroups, function($carry, $group) {
              // Clean up data returned from groups_get_all_groups.
              $userid = $group->userid;
              $groupid = $group->groupid;
  
              unset($group->userid);
              unset($group->groupid);
              $group->id = $groupid;
  
              if (!isset($carry[$userid])) {
                  $carry[$userid] = [$group];
              } else {
                  $carry[$userid][] = $group;
              }
  
              return $carry;
          }, []);
  
          foreach (array_diff(array_keys($authorids), array_keys($authorgroups)) as $authorid) {
              $authorgroups[$authorid] = [];
          }
  
          return $authorgroups;
      }
code: private function get_author_groups_from_posts(array $posts, $forum) : array {
          $course = $forum->get_course_record();
          $coursemodule = $forum->get_course_module_record();
          $authorids = array_reduce($posts, function($carry, $post) {
              $carry[$post->get_author_id()] = true;
              return $carry;
          }, []);
          $authorgroups = groups_get_all_groups($course->id, array_keys($authorids), $coursemodule->groupingid,
                  'g.*, gm.id, gm.groupid, gm.userid');
  
          $authorgroups = array_reduce($authorgroups, function($carry, $group) {
              // Clean up data returned from groups_get_all_groups.
              $userid = $group->userid;
              $groupid = $group->groupid;
  
              unset($group->userid);
              unset($group->groupid);
              $group->id = $groupid;
  
              if (!isset($carry[$userid])) {
                  $carry[$userid] = [$group];
              } else {
                  $carry[$userid][] = $group;
              }
  
              return $carry;
          }, []);
  
          foreach (array_diff(array_keys($authorids), array_keys($authorgroups)) as $authorid) {
              $authorgroups[$authorid] = [];
          }
  
          return $authorgroups;
      }
code_tokens: private function get_author_groups_from_posts ( array $ posts , $ forum ) : array { $ course = $ forum -> get_course_record ( ) ; $ coursemodule = $ forum -> get_course_module_record ( ) ; $ authorids = array_reduce ( $ posts , function ( $ carry , $ post ) { $ carry [ $ post -> get_author_id ( ) ] = true ; return $ carry ; } , [ ] ) ; $ authorgroups = groups_get_all_groups ( $ course -> id , array_keys ( $ authorids ) , $ coursemodule -> groupingid , 'g.*, gm.id, gm.groupid, gm.userid' ) ; $ authorgroups = array_reduce ( $ authorgroups , function ( $ carry , $ group ) { // Clean up data returned from groups_get_all_groups. $ userid = $ group -> userid ; $ groupid = $ group -> groupid ; unset ( $ group -> userid ) ; unset ( $ group -> groupid ) ; $ group -> id = $ groupid ; if ( ! isset ( $ carry [ $ userid ] ) ) { $ carry [ $ userid ] = [ $ group ] ; } else { $ carry [ $ userid ] [ ] = $ group ; } return $ carry ; } , [ ] ) ; foreach ( array_diff ( array_keys ( $ authorids ) , array_keys ( $ authorgroups ) ) as $ authorid ) { $ authorgroups [ $ authorid ] = [ ] ; } return $ authorgroups ; }
docstring: Get the author's groups for a list of posts.
  
  @param post_entity[] $posts The list of posts
  @param forum_entity $forum The forum entity
  @return array Author groups indexed by author id
docstring_tokens: Get the author s groups for a list of posts .