function cf_user_get_users_by_rids in Common Functionality 7
Same name and namespace in other branches
- 7.2 modules/cf_user/cf_user.module \cf_user_get_users_by_rids()
Provide a simple way to load users that have any of the given role ids.
Why: I have not found a way to do this with drupal core functions in a single database transaction.
Parameters
array $rids: an array rid of the role to check to see if a user has the given permission.
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.
File
- modules/
cf_user/ cf_user.module, line 119
Code
function cf_user_get_users_by_rids($rids, array $function_history = array()) {
cf_error_append_history($function_history, __FUNCTION__);
if (!is_array($rids) || empty($rids)) {
cf_error_invalid_array($function_history, 'rids');
return FALSE;
}
$query = db_select('role', 'r');
$query
->innerjoin('users_roles', 'ur', 'r.rid = ur.rid');
$query
->innerjoin('users', 'u', 'u.uid = ur.uid');
$query
->fields('r');
$query
->fields('ur');
$query
->fields('u');
$or = db_or();
foreach ($rids as $rid) {
$or
->condition('ur.rid', $rid, '=');
}
$query
->condition($or);
return $query;
}