function uc_roles_renew in Ubercart 6.2
Same name and namespace in other branches
- 7.3 uc_roles/uc_roles.module \uc_roles_renew()
Renews a given role on a user.
This function updates expiration time on a role already granted to a user. First the function checks the new expiration. If it never expires, the function deletes the past expiration record and returns, leaving management up to Drupal. Otherwise, the record is updated with the new expiration time, and the user is notified of the change.
Parameters
$account: A Drupal user object.
$rid: A Drupal role ID.
$timestamp: When this role will expire.
$silent: When set to TRUE will suppress any Drupal messages from this function.
2 calls to uc_roles_renew()
- uc_roles_action_order_renew in uc_roles/
uc_roles.ca.inc - Renews an orders product roles.
- uc_roles_user_submit in uc_roles/
uc_roles.module - Implements hook_user_submit().
File
- uc_roles/
uc_roles.module, line 1292
Code
function uc_roles_renew($account, $rid, $timestamp, $silent = FALSE) {
global $user;
// If it doesn't expire, we'll remove our data associated with it.
// After that, Drupal will take care of it.
if (is_null($timestamp)) {
uc_roles_delete($account, $rid);
return;
}
// Update the expiration date and reset the notified flag.
db_query("UPDATE {uc_roles_expirations} SET expiration = %d, notified = NULL WHERE uid = %d AND rid = %d", $timestamp, $account->uid, $rid);
if (!$silent) {
$role_name = db_result(db_query('SELECT name FROM {role} WHERE rid = %d', $rid));
if ($user->uid == $account->uid) {
$message = t('Your %role role has been renewed. It will expire on %date.', array(
'%role' => $role_name,
'%date' => format_date($timestamp, 'small'),
));
}
else {
$message = t("%user's %role role has been renewed. It will expire on %date.", array(
'%user' => $account->name,
'%role' => $role_name,
'%date' => format_date($timestamp, 'small'),
));
}
drupal_set_message($message);
}
module_invoke_all('uc_roles_renew', $account, $rid, $timestamp);
}