function regcode_roles_regcode_used in Registration codes 7
Same name and namespace in other branches
- 6.2 regcode_roles/regcode_roles.module \regcode_roles_regcode_used()
- 6 regcode_roles/regcode_roles.module \regcode_roles_regcode_used()
- 7.2 regcode_roles/regcode_roles.module \regcode_roles_regcode_used()
Implements hook_regcode_used().
Add the new role to the user.
File
- regcode_roles/
regcode_roles.module, line 260 - Main functionality of regcode_role module.
Code
function regcode_roles_regcode_used($code, $account) {
// Grab applicable roles for category used.
$rules = regcode_roles_get_rules($code->tags);
// Add the new roles to the user.
foreach ($rules as $rule) {
$account->roles[$rule['role_id']] = $rule['role'];
db_merge('users_roles')
->key(array(
'rid' => $rule['role_id'],
'uid' => $account->uid,
))
->fields(array(
'uid' => $account->uid,
'rid' => $rule['role_id'],
))
->execute();
}
// Apply role_expire rules.
if (module_exists('role_expire')) {
foreach ($rules as $rule) {
if ($rule['expire_date']) {
$expiry_timestamp = $rule['expire_date'];
}
elseif ($rule['expire_duration']) {
$expiry_timestamp = REQUEST_TIME + $rule['expire_duration'] * 60 * 60 * 24;
}
role_expire_write_record($account->uid, $rule['role_id'], $expiry_timestamp);
}
}
}