You are here

function cf_user_get_rids in Common Functionality 7

Same name and namespace in other branches
  1. 7.2 modules/cf_user/cf_user.module \cf_user_get_rids()

Provide a simple way to get the roles ids for the current or specified user.

Returns a query object meant to return all rids for a given uid. This does not call ->execute() on the query object.

Why: The roles stored in the global $user variable are role names and not ids. This provides a way to get user role ids without having to load the user data, process each role, and produce an array of role ids.

Parameters

int $uid: (optional) a uid of the user to get the role ids of if the current user is not to be used.

array $function_history: (optional) An array of function names, ie: array('0' => 'my_function_name').

Return value

object A SelectQuery database object, this object has not been executed.

1 call to cf_user_get_rids()
cf_user_has_role in modules/cf_user/cf_user.module
Provide a simple way to confirm whether or not a user is in a given role by the role id.

File

modules/cf_user/cf_user.module, line 24

Code

function cf_user_get_rids($uid = NULL, array $function_history = array()) {
  cf_error_append_history($function_history, __FUNCTION__);
  if ($uid == NULL) {
    $current_user = cf_current_user();
    $uid = $current_user->uid;
  }
  else {
    if (!is_numeric($uid)) {
      cf_error_not_numeric($function_history, 'uid');
      return FALSE;
    }
  }
  $query = db_select('role', 'r');
  $query
    ->innerjoin('users_roles', 'ur', 'r.rid = ur.rid');
  $query
    ->fields('r');
  $query
    ->fields('ur');
  $and = db_and();
  $and
    ->condition('uid', $uid, '=');
  $query
    ->condition($and);
  return $query;
}