You are here

public function SocialGroupHelperService::getAllGroupsForUser in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getAllGroupsForUser()
  2. 8.4 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getAllGroupsForUser()
  3. 8.5 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getAllGroupsForUser()
  4. 8.6 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getAllGroupsForUser()
  5. 8.7 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getAllGroupsForUser()
  6. 10.3.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getAllGroupsForUser()
  7. 10.0.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getAllGroupsForUser()
  8. 10.1.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getAllGroupsForUser()
  9. 10.2.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getAllGroupsForUser()

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.

File

modules/social_features/social_group/src/SocialGroupHelperService.php, line 156

Class

SocialGroupHelperService
Class SocialGroupHelperService.

Namespace

Drupal\social_group

Code

public function getAllGroupsForUser($uid) {
  $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 = $this->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];
}