You are here

function og_get_membership in Organic groups 7.2

Get the group membership entity by user and group.

Return value

The OgMembership object if found, or FALSE.

15 calls to og_get_membership()
OgAccessModeratedGroup::testMembershipRequest in og_access/og_access.test
Test membership creation attempt made via direct API calls, by non-admins.
OgAccessModeratedGroup::testMemberShipRequestStatusWithState in og_access/og_access.test
Test that membership requests made via direct API calls that include membership state result in proper active status for private groups that require approval.
OgBehaviorHandlerTestCase::testGroupAudienceField in ./og.test
Test piping group association via the group-audience field.
OgGroupAndUngroup::testGroupAndUngroup in ./og.test
Test group and ungroup of content.
OgGroupAndUngroup::testGroupManagerNotActive in ./og.test
Test group behaviour when the group owner is not active.

... See full list

1 string reference to 'og_get_membership'
og_invalidate_cache in ./og.module
Invalidate cache.

File

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

Code

function og_get_membership($group_type, $gid, $entity_type, $etid) {
  $return =& drupal_static(__FUNCTION__, array());
  $identifier = $group_type . ':' . $gid . ':' . $entity_type . ':' . $etid;
  if (!isset($return[$identifier])) {
    $return[$identifier] = FALSE;
    $query = new EntityFieldQuery();
    $result = $query
      ->entityCondition('entity_type', 'og_membership')
      ->propertyCondition('gid', $gid, '=')
      ->propertyCondition('group_type', $group_type, '=')
      ->propertyCondition('etid', $etid, '=')
      ->propertyCondition('entity_type', $entity_type, '=')
      ->execute();
    if (!empty($result['og_membership'])) {
      $key = key($result['og_membership']);
      $return[$identifier] = $key;
    }
  }
  if (!empty($return[$identifier])) {
    $og_membership = og_membership_load($return[$identifier]);
    return $og_membership;
  }
  return FALSE;
}