You are here

function group_load_by_member in Group 7

Load all groups for a given user.

Parameters

int $uid: The id of the user.

string $type: (optional) Filters the results by a group type.

Return value

array An array of Group entities, keyed by their group ids.

2 calls to group_load_by_member()
gnode_group_node_create_access in modules/gnode/gnode.module
Determines whether a user could create a node in a Group context.
gnode_group_node_create_gids in modules/gnode/gnode.module
Retrieve all group ids a user can create a node of a given type in.

File

helpers/group.entity.inc, line 99
Entity API related helper functions for groups.

Code

function group_load_by_member($uid, $type = NULL) {
  $gids = array();
  foreach (group_membership_load_by_user($uid) as $group_membership) {
    $gids[] = $group_membership->gid;
  }
  $groups = group_load_multiple($gids);
  if ($type) {
    foreach ($groups as $gid => $group) {
      if ($group->type !== $type) {
        unset($groups[$gid]);
      }
    }
  }
  return $groups;
}