You are here

function role_expire_set_default_duration in Role Expire 7

Same name and namespace in other branches
  1. 6 role_expire.module \role_expire_set_default_duration()

API function; Set the default expiry duration for a role.

Parameters

$rid: Role ID.

$duration: The strtotime-compatible duration string.

2 calls to role_expire_set_default_duration()
role_expire_migrate_complete_role in ./role_expire.migrate.inc
Implementation of hook_migrate_prepare_role().
role_expire_user_admin_role_submit in ./role_expire.module
Form submit handler invoked by role_expire_form_user_admin_role_alter. Updates default duration in database.

File

./role_expire.module, line 155
Role Expire module

Code

function role_expire_set_default_duration($rid, $duration) {
  if (!empty($duration)) {

    // Do we have a value already?
    $prev_duration = role_expire_get_default_duration($rid);

    // If we have a previous duration, attempt to do an UPDATE.
    if ($prev_duration) {
      $result = db_update('role_expire_length')
        ->fields(array(
        'duration' => check_plain($duration),
      ))
        ->condition('rid', $rid)
        ->execute();
    }
    else {
      $id = db_insert('role_expire_length')
        ->fields(array(
        'rid' => $rid,
        'duration' => check_plain($duration),
      ))
        ->execute();
    }
  }
}