function apply_for_role_available_roles in Apply for role 6
Same name and namespace in other branches
- 5 apply_for_role.module \apply_for_role_available_roles()
- 7.2 apply_for_role.module \apply_for_role_available_roles()
- 7 apply_for_role.module \apply_for_role_available_roles()
Return an array of the roles that are available for application by a user.
Parameters
$user User object:
Return value
array keyed by role id with the role names as values.
1 call to apply_for_role_available_roles()
- apply_for_role_apply_form in ./
apply_for_role.module - Implementation of hook_form().
File
- ./
apply_for_role.module, line 364 - Allows users to apply for roles.
Code
function apply_for_role_available_roles($user) {
// Get the complete list of roles (other than anonyous)...
$roles = user_roles(TRUE);
// ...the roles that can be applied for...
$enabled = (array) variable_get('users_apply_roles', array());
// Check that all of the enabled roles exist.
// TODO: Catch these when they are deleted.
$enabled = array_intersect($roles, $enabled);
// ...the roles the user has already applied for...
$applied = array();
$result = db_query("SELECT rid FROM {users_roles_apply} WHERE uid = %d", $user->uid);
while ($row = db_fetch_object($result)) {
$applied[$row->rid] = isset($roles[$row->rid]) ? $roles[$row->rid] : t('Invalid role');
}
// ... now figure out what's left from the enabled roles list once you remove
// those they have and those they've applied for.
$used = $user->roles + $applied;
return array_diff($enabled, $used);
}