You are here

function og_get_properties in Organic groups 7

Property getter callback.

See also

OgMetadataController

OgMembershipMetadataController

og_entity_property_info()

2 string references to 'og_get_properties'
OgMetadataController::entityPropertyInfo in includes/og.info.inc
og_entity_property_info in ./og.module
Implements hook_entity_property_info().

File

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

Code

function og_get_properties($entity, array $options, $name, $type) {
  switch ($name) {
    case 'manager':
      return ($account = $entity
        ->user()) ? $account : NULL;
    case 'members':
      $return = array();
      if (!empty($entity->gid)) {
        $query = new EntityFieldQuery();
        $query
          ->entityCondition('entity_type', 'user')
          ->fieldCondition(OG_AUDIENCE_FIELD, 'gid', $entity->gid, '=');
        $result = $query
          ->execute();
        if (!empty($result['user'])) {
          $return = array_keys($result['user']);
        }
      }
      return $return;
    case 'og_membership':
      list($id) = entity_extract_ids($type, $entity);
      $query = new EntityFieldQuery();
      $result = $query
        ->entityCondition('entity_type', 'og_membership')
        ->propertyCondition('entity_type', $type, '=')
        ->propertyCondition('etid', $id, '=')
        ->execute();
      return !empty($result['og_membership']) ? array_keys($result['og_membership']) : array();
    case 'url':
      $group = $entity;
      $entity_from_group = $group
        ->getEntity();
      $return = entity_uri($group->entity_type, $entity_from_group);
      return url($return['path'], $return['options'] + $options);
    case 'group':
      list($id) = entity_extract_ids($type, $entity);
      $group = og_get_group($type, $id);
      return $group ? $group : NULL;
  }
}