function simple_ldap_user_class_attrs_as_options in Simple LDAP 7.2
Given an array of objectClasses, return an array with the attributes in a hierarchy, grouped by objectClass, and suitable for FAPI select elements.
Parameters
array: An array of classes.
Return value
array An array of attributes to be fed to FAPI select elements.
2 calls to simple_ldap_user_class_attrs_as_options()
- simple_ldap_user_admin in simple_ldap_user/
simple_ldap_user.admin.inc - Simple LDAP User configuration form.
- simple_ldap_user_profile_map_form in simple_ldap_user/
simple_ldap_user.admin.inc - Admin form for mapping Drupal user attributes to LDAP attributes
File
- simple_ldap_user/
simple_ldap_user.module, line 1270 - Main simple_ldap_user module file.
Code
function simple_ldap_user_class_attrs_as_options($classes) {
// Get an LDAP server object.
$server = SimpleLdapServer::singleton();
// Verify LDAP server connectivity, return NULL (error) if unable to bind
if (!$server
->bind()) {
return NULL;
}
// Pull the available LDAP schemas from the server
$schema = $server->schema;
// Build a list of available LDAP attributes, grouped by Object Class
$options[''] = ' - None - ';
foreach ($classes as $class) {
if ($class == 'top') {
continue;
}
// Add a * to must attributes, to indiciate it must be set.
$ldap_must_attrs = $schema
->must($class);
foreach ($ldap_must_attrs as $attribute) {
$options[$class][strtolower($attribute)] = $attribute . '*';
}
// Add the may attributes later.
foreach ($schema
->may($class) as $attribute) {
$options[$class][strtolower($attribute)] = $attribute;
}
}
return $options;
}