You are here

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

Same name and namespace in other branches
  1. 8.2 ldap_authorization/ldap_authorization_drupal_role/LdapAuthorizationConsumerRole.class.php \LdapAuthorizationConsumerDrupalRole::populateConsumersFromConsumerIds()

Overrides LdapAuthorizationConsumerAbstract::populateConsumersFromConsumerIds

See also

LdapAuthorizationConsumerAbstract::populateConsumersFromConsumerIds

File

ldap_authorization/ldap_authorization_drupal_role/LdapAuthorizationConsumerRole.class.php, line 70

Class

LdapAuthorizationConsumerDrupalRole

Code

public function populateConsumersFromConsumerIds(&$consumers, $create_missing_consumers = FALSE) {
  $roles_by_consumer_id = $this
    ->existingRolesByRoleName(TRUE);
  foreach ($consumers as $consumer_id => $consumer) {

    // Role marked as not existing.
    if (!$consumer['exists']) {

      // Check if is existing.
      if (isset($roles_by_consumer_id[$consumer_id])) {
        $consumer['exists'] = TRUE;
        $consumer['value'] = $roles_by_consumer_id[$consumer_id]['role_name'];
        $consumer['name'] = $consumer['map_to_string'];
        $consumer['map_to_string'] = $roles_by_consumer_id[$consumer_id]['role_name'];
      }
      elseif ($create_missing_consumers) {
        $consumer['value'] = $consumer['map_to_string'];
        $consumer['name'] = $consumer['map_to_string'];
        $result = $this
          ->createConsumer($consumer_id, $consumer);
        $consumer['exists'] = $result;
      }
      else {
        $consumer['exists'] = FALSE;
      }
    }
    elseif (empty($consumer['value'])) {
      $consumer['value'] = $roles_by_consumer_id[$consumer_id]['role_name'];
    }
    $consumers[$consumer_id] = $consumer;
  }
}