function og_get_groups_by_user in Organic groups 7
Same name and namespace in other branches
- 7.2 og.module \og_get_groups_by_user()
Get the group IDs of all the groups a user is an approved member of.
Parameters
$account: Optional; The user object to fetch group memberships for. Defaults to the acting user.
Return value
An array with the group IDs or an empty array.
1 call to og_get_groups_by_user()
- og_plugin_argument_default_user_groups::get_argument in includes/
views/ og_plugin_argument_default_user_groups.inc - Get the default argument.
File
- ./
og.module, line 3243 - Enable users to create and manage groups with roles and permissions.
Code
function og_get_groups_by_user($account = NULL) {
if (empty($account)) {
global $user;
$account = $user;
}
$gids = array();
// Get all active OG membership that belong to the user.
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', 'og_membership')
->propertyCondition('entity_type', 'user')
->propertyCondition('etid', $account->uid)
->propertyCondition('state', OG_STATE_ACTIVE)
->execute();
if (!empty($result['og_membership'])) {
$memberships = og_membership_load_multiple(array_keys($result['og_membership']));
foreach ($memberships as &$membership) {
$gids[] = $membership->gid;
}
}
return $gids;
}