original_string: public function check_group_membership($otheruserid) {
          global $USER;
  
          if (groups_get_activity_groupmode($this->cm) != SEPARATEGROUPS) {
              // The workshop is not in a group mode, or it is in a visible group mode.
              return true;
  
          } else if (has_capability('moodle/site:accessallgroups', $this->context)) {
              // The current user can access all groups.
              return true;
  
          } else {
              $thisusersgroups = groups_get_all_groups($this->course->id, $USER->id, $this->cm->groupingid, 'g.id');
              $otherusersgroups = groups_get_all_groups($this->course->id, $otheruserid, $this->cm->groupingid, 'g.id');
              $commongroups = array_intersect_key($thisusersgroups, $otherusersgroups);
  
              if (empty($commongroups)) {
                  // The current user has no group common with the other user.
                  return false;
  
              } else {
                  // The current user has a group common with the other user.
                  return true;
              }
          }
      }
code: public function check_group_membership($otheruserid) {
          global $USER;
  
          if (groups_get_activity_groupmode($this->cm) != SEPARATEGROUPS) {
              // The workshop is not in a group mode, or it is in a visible group mode.
              return true;
  
          } else if (has_capability('moodle/site:accessallgroups', $this->context)) {
              // The current user can access all groups.
              return true;
  
          } else {
              $thisusersgroups = groups_get_all_groups($this->course->id, $USER->id, $this->cm->groupingid, 'g.id');
              $otherusersgroups = groups_get_all_groups($this->course->id, $otheruserid, $this->cm->groupingid, 'g.id');
              $commongroups = array_intersect_key($thisusersgroups, $otherusersgroups);
  
              if (empty($commongroups)) {
                  // The current user has no group common with the other user.
                  return false;
  
              } else {
                  // The current user has a group common with the other user.
                  return true;
              }
          }
      }
code_tokens: public function check_group_membership ( $ otheruserid ) { global $ USER ; if ( groups_get_activity_groupmode ( $ this -> cm ) != SEPARATEGROUPS ) { // The workshop is not in a group mode, or it is in a visible group mode. return true ; } else if ( has_capability ( 'moodle/site:accessallgroups' , $ this -> context ) ) { // The current user can access all groups. return true ; } else { $ thisusersgroups = groups_get_all_groups ( $ this -> course -> id , $ USER -> id , $ this -> cm -> groupingid , 'g.id' ) ; $ otherusersgroups = groups_get_all_groups ( $ this -> course -> id , $ otheruserid , $ this -> cm -> groupingid , 'g.id' ) ; $ commongroups = array_intersect_key ( $ thisusersgroups , $ otherusersgroups ) ; if ( empty ( $ commongroups ) ) { // The current user has no group common with the other user. return false ; } else { // The current user has a group common with the other user. return true ; } } }
docstring: Check if the current user can access the other user's group.
  
  This is typically used for teacher roles that have permissions like
  'view all submissions'. Even with such a permission granted, we have to
  check the workshop activity group mode.
  
  If the workshop is not in a group mode, or if it is in the visible group
  mode, this method returns true. This is consistent with how the
  {@link groups_get_activity_allowed_groups()} behaves.
  
  If the workshop is in a separate group mode, the current user has to
  have the 'access all groups' permission, or share at least one
  accessible group with the other user.
  
  @param int $otheruserid The ID of the other user, e.g. the author of a submission.
  @return bool False if the current user cannot access the other user's group.
docstring_tokens: Check if the current user can access the other user s group .