function og_subgroups_get_users_group in Subgroups for Organic groups 7.2
Get users that are associated with a group.
Parameters
$entity_type: The entity type. Defaults to 'node'.
$entity: Optional; The entity object or entity ID.
$states: Optional; Array with the state to return. Defaults to active.
Return value
An array with the entities' entity type as the key, and array - keyed by the OG membership ID and the Entity ID as the value. If nothing found, then an empty array.
1 call to og_subgroups_get_users_group()
- _og_subgroups_get_inherited_users in ./
og_subgroups.common.inc - Return an array of inherited users from the parent groups that allow for user inheritance.
File
- ./
og_subgroups.common.inc, line 81 - Common functions used in og_subgroups.
Code
function og_subgroups_get_users_group($entity_type = 'node', $entity = NULL, $states = array(
OG_STATE_ACTIVE,
)) {
$cache =& drupal_static(__FUNCTION__, array());
if (is_object($entity)) {
// Get the entity ID.
list($id) = entity_extract_ids($entity_type, $entity);
}
else {
$id = is_numeric($entity) ? $entity : 0;
}
// Get a string identifier of the states, so we can retrieve it from cache.
if ($states) {
sort($states);
$state_identifier = implode(':', $states);
}
else {
$state_identifier = 0;
}
if (isset($cache[$entity_type][$id][$state_identifier])) {
// Return cached values.
return $cache[$entity_type][$id][$state_identifier];
}
$cache[$entity_type][$id][$state_identifier] = array();
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'og_membership', '=')
->propertyCondition('entity_type', 'user', '=')
->propertyCondition('group_type', $entity_type, '=')
->propertyCondition('gid', $id, '=');
if ($states) {
$query
->propertyCondition('state', $states, 'IN');
}
$result = $query
->execute();
if (!empty($result['og_membership'])) {
// Get the group ID from the group membership.
$og_memberships = og_membership_load_multiple(array_keys($result['og_membership']));
foreach ($og_memberships as $og_membership) {
$cache[$entity_type][$id][$state_identifier]['user'][$og_membership->id] = $og_membership->etid;
}
}
return $cache[$entity_type][$id][$state_identifier];
}