You are here

function og_get_group_members_properties in Organic groups 7.2

Property getter callback for group members.

See also

og_entity_property_info()

1 string reference to 'og_get_group_members_properties'
og_entity_property_info in ./og.module
Implements hook_entity_property_info().

File

./og.module, line 286
Enable users to create and manage groups with roles and permissions.

Code

function og_get_group_members_properties($entity, array $options, $name, $type) {
  $args = explode('__', $name);
  $state = !empty($args[1]) ? $args[1] : FALSE;
  list($id) = entity_extract_ids($type, $entity);
  $cache =& drupal_static(__FUNCTION__, array());
  if (isset($cache[$type][$id][$state])) {

    // Return the cached result.
    return $cache[$type][$id][$state];
  }
  $cache[$type][$id][$state] = array();
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'og_membership')
    ->propertyCondition('group_type', $type, '=')
    ->propertyCondition('gid', $id, '=')
    ->propertyCondition('entity_type', 'user', '=');
  if ($state) {
    $query
      ->propertyCondition('state', $state, '=');
  }
  $result = $query
    ->execute();
  if (!empty($result['og_membership'])) {
    $og_memberships = og_membership_load_multiple(array_keys($result['og_membership']));
    foreach ($og_memberships as $og_membership) {
      $cache[$type][$id][$state][] = $og_membership->etid;
    }
  }
  return $cache[$type][$id][$state];
}