You are here

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

Same name and namespace in other branches
  1. 8.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 182

Class

LdapAuthorizationConsumerOG

Code

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

  // Generate a query for all og groups of interest.
  $gids = [];
  foreach ($consumers as $consumer_id => $consumer) {
    list($entity_type, $gid, $rid) = explode(':', $consumer_id);
    $gids[$entity_type][] = $gid;
  }
  foreach ($gids as $entity_type => $gid_x_entity) {
    if ($entity_type !== NULL) {
      $og_group_entities[$entity_type] = @entity_load($entity_type, $gid_x_entity);
    }
    else {
      watchdog("ldap_authorization_og", "Entity type of 'NULL' found while populating consumers.", WATCHDOG_ERROR);
    }
  }
  foreach ($consumers as $consumer_id => $consumer) {
    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;
  }
}