You are here

public function LdapAuthorizationConsumerOG::populateConsumersFromConsumerIds in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php \LdapAuthorizationConsumerOG::populateConsumersFromConsumerIds()

Overrides LdapAuthorizationConsumerAbstract::populateConsumersFromConsumerIds

See also

LdapAuthorizationConsumerAbstract::populateConsumersFromConsumerIds

File

ldap_authorization/ldap_authorization_og/LdapAuthorizationConsumerOG.class.php, line 290

Class

LdapAuthorizationConsumerOG

Code

public function populateConsumersFromConsumerIds(&$consumers, $create_missing_consumers = FALSE) {

  // generate a query for all og groups of interest
  $gids = array();
  foreach ($consumers as $consumer_id => $consumer) {
    if (ldap_authorization_og_og_version() == 1) {
      list($gid, $rid) = $this
        ->og1ConsumerIdParts($consumer_id);
      $gids[] = $gid;
    }
    else {
      list($entity_type, $gid, $rid) = explode(':', $consumer_id);
      $gids[$entity_type][] = $gid;
    }
  }
  if (ldap_authorization_og_og_version() == 1) {
    $og_group_entities = og_load_multiple($gids);
  }
  else {
    foreach ($gids as $entity_type => $gid_x_entity) {
      $og_group_entities[$entity_type] = @entity_load($entity_type, $gid_x_entity);
    }
  }
  foreach ($consumers as $consumer_id => $consumer) {
    if (ldap_authorization_og_og_version() == 1) {
      list($gid, $rid) = $this
        ->og1ConsumerIdParts($consumer_id);
      $consumer['exists'] = isset($og_group_entities[$gid]);
      if ($consumer['exists']) {
        $consumer['value'] = $og_group_entities[$gid];
        if (empty($consumer['name']) && property_exists($og_group_entities[$gid], 'title')) {
          $consumer['name'] = $og_group_entities[$gid]->title;
        }
        $consumer['name'] = $consumer_id;
      }
      else {
        $consumer['value'] = NULL;
        $consumer['name'] = NULL;
      }
      $consumer['map_to_string'] = $consumer_id;
    }
    else {
      list($entity_type, $gid, $rid) = explode(':', $consumer_id);
      $consumer['exists'] = isset($og_group_entities[$entity_type][$gid]);
      $consumer['value'] = $consumer['exists'] ? $og_group_entities[$entity_type][$gid] : NULL;
      $consumer['map_to_string'] = $consumer_id;
      if (empty($consumer['name']) && !empty($og_group_entities[$entity_type][$gid]) && property_exists($og_group_entities[$entity_type][$gid], 'title')) {
        $consumer['name'] = $og_group_entities[$entity_type][$gid]->title;
      }
    }
    if (!$consumer['exists'] && $create_missing_consumers) {

      // @todo if creation of og groups were implemented, function would be called here
      // this would mean mapping would need to have enough info to configure a group,
      // or settings would need to include a default group type to create (entity type,
      // bundle, etc.)
    }
    $consumers[$consumer_id] = $consumer;
  }
}