You are here

function invite_target_roles in Invite 7.4

Same name and namespace in other branches
  1. 6.2 invite.module \invite_target_roles()
  2. 7.2 invite.module \invite_target_roles()

Determine target roles based on the roles of an inviter.

Parameters

Invite $invite: An invite object.

$account: The user for whom the role is being determined.

Return value

array Array of target roles for an invited user.

1 call to invite_target_roles()
invite_user_presave in ./invite.module
Implements hook_user_presave().

File

./invite.module, line 864

Code

function invite_target_roles($invite, $account) {
  $targets = array();
  $invite = entity_metadata_wrapper('invite', $invite);
  $inviter = user_load($invite->inviter->uid
    ->value());

  // Add roles of inviter.
  $roles = array_intersect($inviter->roles, user_roles(TRUE, 'send invitations'));

  // Add a dummy entry to retrieve the default target role setting.
  $roles['default'] = 'default';

  // Map to configured target roles.
  foreach ($roles as $rid => $role) {
    $target = variable_get('invite_target_role_' . $rid, DRUPAL_AUTHENTICATED_RID);
    if ($target != DRUPAL_AUTHENTICATED_RID) {
      $targets[$target] = $target;
    }
  }
  drupal_alter('invite_target_roles', $targets, $invite, $account);
  return $targets;
}