function cf_user_get_users_by_rids in Common Functionality 7.2
Same name and namespace in other branches
- 7 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.
Justification: 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.
Return value
object A SelectQuery database object, this object has not been executed.
Related topics
File
- modules/
cf_user/ cf_user.module, line 186 - Common Functionality - User module.
Code
function cf_user_get_users_by_rids($rids) {
if (!is_array($rids) || empty($rids)) {
if (class_exists('cf_error')) {
cf_error::invalid_array('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;
}