original_string: private function get_author_groups_from_posts(array $groupedposts) : array {
          $groupsbyauthorid = [];
          $authoridsbycourseid = [];
  
          // Get the unique list of author ids for each course in the grouped
          // posts. Grouping by course is the largest grouping we can achieve.
          foreach ($groupedposts as $grouping) {
              ['forum' => $forum, 'posts' => $posts] = $grouping;
              $course = $forum->get_course_record();
              $courseid = $course->id;
  
              if (!isset($authoridsbycourseid[$courseid])) {
                  $coursemodule = $forum->get_course_module_record();
                  $authoridsbycourseid[$courseid] = [
                      'groupingid' => $coursemodule->groupingid,
                      'authorids' => []
                  ];
              }
  
              $authorids = array_map(function($post) {
                  return $post->get_author_id();
              }, $posts);
  
              foreach ($authorids as $authorid) {
                  $authoridsbycourseid[$courseid]['authorids'][$authorid] = $authorid;
              }
          }
  
          // Load each set of groups per course.
          foreach ($authoridsbycourseid as $courseid => $values) {
              ['groupingid' => $groupingid, 'authorids' => $authorids] = $values;
              $authorgroups = groups_get_all_groups(
                  $courseid,
                  array_keys($authorids),
                  $groupingid,
                  'g.*, gm.id, gm.groupid, gm.userid'
              );
  
              if (!isset($groupsbyauthorid[$courseid])) {
                  $groupsbyauthorid[$courseid] = [];
              }
  
              foreach ($authorgroups as $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($groupsbyauthorid[$courseid][$userid])) {
                      $groupsbyauthorid[$courseid][$userid] = [];
                  }
  
                  $groupsbyauthorid[$courseid][$userid][] = $group;
              }
          }
  
          return $groupsbyauthorid;
      }
code: private function get_author_groups_from_posts(array $groupedposts) : array {
          $groupsbyauthorid = [];
          $authoridsbycourseid = [];
  
          // Get the unique list of author ids for each course in the grouped
          // posts. Grouping by course is the largest grouping we can achieve.
          foreach ($groupedposts as $grouping) {
              ['forum' => $forum, 'posts' => $posts] = $grouping;
              $course = $forum->get_course_record();
              $courseid = $course->id;
  
              if (!isset($authoridsbycourseid[$courseid])) {
                  $coursemodule = $forum->get_course_module_record();
                  $authoridsbycourseid[$courseid] = [
                      'groupingid' => $coursemodule->groupingid,
                      'authorids' => []
                  ];
              }
  
              $authorids = array_map(function($post) {
                  return $post->get_author_id();
              }, $posts);
  
              foreach ($authorids as $authorid) {
                  $authoridsbycourseid[$courseid]['authorids'][$authorid] = $authorid;
              }
          }
  
          // Load each set of groups per course.
          foreach ($authoridsbycourseid as $courseid => $values) {
              ['groupingid' => $groupingid, 'authorids' => $authorids] = $values;
              $authorgroups = groups_get_all_groups(
                  $courseid,
                  array_keys($authorids),
                  $groupingid,
                  'g.*, gm.id, gm.groupid, gm.userid'
              );
  
              if (!isset($groupsbyauthorid[$courseid])) {
                  $groupsbyauthorid[$courseid] = [];
              }
  
              foreach ($authorgroups as $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($groupsbyauthorid[$courseid][$userid])) {
                      $groupsbyauthorid[$courseid][$userid] = [];
                  }
  
                  $groupsbyauthorid[$courseid][$userid][] = $group;
              }
          }
  
          return $groupsbyauthorid;
      }
code_tokens: private function get_author_groups_from_posts ( array $ groupedposts ) : array { $ groupsbyauthorid = [ ] ; $ authoridsbycourseid = [ ] ; // Get the unique list of author ids for each course in the grouped // posts. Grouping by course is the largest grouping we can achieve. foreach ( $ groupedposts as $ grouping ) { [ 'forum' => $ forum , 'posts' => $ posts ] = $ grouping ; $ course = $ forum -> get_course_record ( ) ; $ courseid = $ course -> id ; if ( ! isset ( $ authoridsbycourseid [ $ courseid ] ) ) { $ coursemodule = $ forum -> get_course_module_record ( ) ; $ authoridsbycourseid [ $ courseid ] = [ 'groupingid' => $ coursemodule -> groupingid , 'authorids' => [ ] ] ; } $ authorids = array_map ( function ( $ post ) { return $ post -> get_author_id ( ) ; } , $ posts ) ; foreach ( $ authorids as $ authorid ) { $ authoridsbycourseid [ $ courseid ] [ 'authorids' ] [ $ authorid ] = $ authorid ; } } // Load each set of groups per course. foreach ( $ authoridsbycourseid as $ courseid => $ values ) { [ 'groupingid' => $ groupingid , 'authorids' => $ authorids ] = $ values ; $ authorgroups = groups_get_all_groups ( $ courseid , array_keys ( $ authorids ) , $ groupingid , 'g.*, gm.id, gm.groupid, gm.userid' ) ; if ( ! isset ( $ groupsbyauthorid [ $ courseid ] ) ) { $ groupsbyauthorid [ $ courseid ] = [ ] ; } foreach ( $ authorgroups as $ 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 ( $ groupsbyauthorid [ $ courseid ] [ $ userid ] ) ) { $ groupsbyauthorid [ $ courseid ] [ $ userid ] = [ ] ; } $ groupsbyauthorid [ $ courseid ] [ $ userid ] [ ] = $ group ; } } return $ groupsbyauthorid ; }
docstring: Get the groups for each author of the given posts.
  
  The results are grouped by course and then author id because the groups are
  contextually related to the course, e.g. a single author can be part of two different
  sets of groups in two different courses.
  
  @param array $groupedposts List of posts grouped by discussions.
  @return array List of groups indexed by forum id and then author id.
docstring_tokens: Get the groups for each author of the given posts .