function apply_for_role_process_applications in Apply for role 7
Same name and namespace in other branches
- 5 apply_for_role.module \apply_for_role_process_applications()
- 6 apply_for_role.module \apply_for_role_process_applications()
- 7.2 apply_for_role.module \apply_for_role_process_applications()
Process an application and store it for admin review.
Parameters
$user: A user object.
$applications: Mixed, either a role ID or an array keyed by role ID.
$message: A string containing the applicant's reason for the role request.
2 calls to apply_for_role_process_applications()
- apply_for_role_apply_form_submit in ./
apply_for_role.module - Submit callback for apply for role form.
- apply_for_role_user_insert in ./
apply_for_role.module - Implements hook_user_insert().
File
- ./
apply_for_role.module, line 630 - Allows users to apply for roles.
Code
function apply_for_role_process_applications($user, $applications, $message = NULL) {
$roles = user_roles(TRUE);
// They can hand in either an array keyed by role id or single role id.
// Ensure we've got an array keyed by role id with the name as the value.
if (is_array($applications)) {
// Filter out any thing with empty role names. And use the official role
// name.
$applications = array_intersect_key($roles, array_filter($applications));
}
else {
$applications = array(
$applications => $roles[$applications],
);
}
$received = array();
$not_received = array();
foreach ($applications as $rid => $role) {
if (apply_for_role_add_apply($user, $rid, $message)) {
$received[] = $role;
}
else {
$not_received[] = $role;
}
}
if (!empty($received)) {
drupal_set_message(format_plural(count($received), 'Your application was received for: %roles', 'Your applications were received for: %roles', array(
'%roles' => implode(', ', $received),
)));
}
if (!empty($not_received)) {
drupal_set_message(format_plural(count($not_received), 'There was a problem processing your application for: %roles', 'There was a problem processing your applications for: %roles', array(
'%roles' => implode(', ', $not_received),
)), 'error');
}
}