You are here

function social_group_get_all_group_members in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  2. 8 modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  3. 8.2 modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  4. 8.3 modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  5. 8.4 modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  6. 8.5 modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  7. 8.6 modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  8. 8.7 modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  9. 8.8 modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  10. 10.3.x modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  11. 10.0.x modules/social_features/social_group/social_group.module \social_group_get_all_group_members()
  12. 10.1.x modules/social_features/social_group/social_group.module \social_group_get_all_group_members()

Get all group memberships for a certain user.

Parameters

int $uid: The UID for which we fetch the groups it is member of.

Return value

array List of group IDs the user is member of.

Deprecated

in social:8.x-4.2 and is removed from social:8.x-9.6. This function is moved to the service social_group.helper_service, use getAllGroupsForUser() instead.

See also

https://www.drupal.org/node/3026220

File

modules/social_features/social_group/social_group.module, line 1774
The Social group module.

Code

function social_group_get_all_group_members($uid) {
  @trigger_error(__FUNCTION__ . ' is deprecated in social:8.x-4.2 and is removed from social:8.x-9.6. This function is moved to the service social_group.helper_service, use getAllGroupsForUser() instead. See https://www.drupal.org/node/3026220', E_USER_DEPRECATED);
  $groups =& drupal_static(__FUNCTION__);

  // Get the memberships for the user if they aren't known yet.
  if (!isset($groups[$uid])) {
    $group_content_types = GroupContentType::loadByEntityTypeId('user');
    $group_content_types = array_keys($group_content_types);
    $query = \Drupal::database()
      ->select('group_content_field_data', 'gcfd');
    $query
      ->addField('gcfd', 'gid');
    $query
      ->condition('gcfd.entity_id', $uid);
    $query
      ->condition('gcfd.type', $group_content_types, 'IN');
    $query
      ->execute()
      ->fetchAll();
    $group_ids = $query
      ->execute()
      ->fetchAllAssoc('gid');
    $groups[$uid] = array_keys($group_ids);
  }
  return $groups[$uid];
}