You are here

function apply_for_role_process_applications in Apply for role 6

Same name and namespace in other branches
  1. 5 apply_for_role.module \apply_for_role_process_applications()
  2. 7.2 apply_for_role.module \apply_for_role_process_applications()
  3. 7 apply_for_role.module \apply_for_role_process_applications()

Process an application and store it for admin review.

Parameters

$user User object.:

$applications Mixed, either a role id or an array keyed by role id.:

2 calls to apply_for_role_process_applications()
apply_for_role_apply_form_submit in ./apply_for_role.module
apply_for_role_user in ./apply_for_role.module
Implementation of hook_user().

File

./apply_for_role.module, line 501
Allows users to apply for roles.

Code

function apply_for_role_process_applications($user, $applications) {
  $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)) {
      $received[] = $role;
    }
    else {
      $not_received[] = $role;
    }
  }
  if (!empty($received)) {
    drupal_set_message(format_plural(count($received), 'Your application was received for the following role:', 'Your applications were received for the following 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 the following role:', 'There was a problem processing your applications for the following roles:', array(
      '%roles' => implode(', ', $not_received),
    )), 'error');
  }
}