function _invite_role_escalate in Invite 5
Escalates an invited user's role(s), based on the role(s) of the inviter.
Parameters
$invitee: A user object.
1 call to _invite_role_escalate()
- invite_user in ./
invite.module - Implementation of hook_user().
File
- ./
invite.module, line 1256 - Allows your users to send and track invitations to join your site.
Code
function _invite_role_escalate($invitee) {
// Default target role
$roles = array(
'default',
);
// Add roles of inviter
$inviter_uid = db_result(db_query("SELECT uid FROM {invite} WHERE mid = %d", $invitee->uid));
if ($inviter_uid && ($inviter = user_load(array(
'uid' => $inviter_uid,
)))) {
$roles = array_merge($roles, array_intersect($inviter->roles, user_roles(0, 'send invitations')));
}
// Map to configured target roles
$targets = array();
foreach ($roles as $role) {
$role_no_space = str_replace(' ', '_', $role);
$target = variable_get('invite_target_role_' . $role_no_space, DRUPAL_AUTHENTICATED_RID);
if ($target != DRUPAL_AUTHENTICATED_RID) {
$targets[$target] = $target;
}
}
// Notify other modules of changed user
$edit = array(
'roles' => $targets,
);
user_module_invoke('update', $edit, $invitee);
// Save new user role(s)
foreach ($targets as $target) {
db_query("DELETE FROM {users_roles} WHERE uid = %d AND rid = %d", $invitee->uid, $target);
db_query("INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)", $invitee->uid, $target);
}
// Notify other modules of role escalation
$args = array(
'invitee' => $invitee,
'inviter' => $inviter,
'roles' => $targets,
);
module_invoke_all('invite', 'escalate', $args);
}