You are here

function ldap_authorization_og2_get_group_from_name in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_authorization/ldap_authorization_og/ldap_authorization_og.module \ldap_authorization_og2_get_group_from_name()

Generic function to convert between query values and organic groups structures and attributes

Parameters

mixed $value signifies query value e.g. 'bakers', 7 etc.:

mixed $value_type signifies query type e.g. 'group_name', 'gid', etc.:

string $return signifying return type. e.g. 'object', 'label', 'name', 'gid':

Return value

mixed organic group object, gid, label, etc.

3 calls to ldap_authorization_og2_get_group_from_name()
LdapAuthorizationConsumerOG::normalizeMappings in ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php
LdapAuthorizationOg2Tests::getTestData in ldap_authorization/tests/Og2Tests.test
get test data in convenient format, so tests are easier to read and write
LdapAuthorizationOg2Tests::testBasicFunctionsAndApi in ldap_authorization/tests/Og2Tests.test
just make sure install succeeds and

File

ldap_authorization/ldap_authorization_og/ldap_authorization_og.module, line 149
controls organic group membership based on LDAP values

Code

function ldap_authorization_og2_get_group_from_name($entity_type, $group_name) {
  require_once drupal_get_path('module', 'ldap_authorization_og') . '/LdapAuthorizationConsumerOG.class.php';
  $group_entity = FALSE;
  $group_entity_id = FALSE;
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', $entity_type)
    ->propertyCondition('title', $group_name);
  $result = $query
    ->execute();
  if (isset($result[$entity_type])) {
    $group_ids = array_keys($result[$entity_type]);
    if (count($group_ids) == 1) {
      $group_entity = entity_load_single($entity_type, $group_ids[0]);
      $group_entity_id = $group_ids[0];
    }
  }
  return array(
    $group_entity,
    $group_entity_id,
  );
}