Get Users with given user roles and organic group

Public

Call this function with user role id and organic group id to get users in that combination.

Get raw version
php
  1. function get_users_on_role_and_group_basis($rid, $gid) {
  2. $users = entity_load('user');
  3. foreach($users as $user) {
  4. if(is_array($user->og_user_node)) {
  5. if (array_key_exists($rid, $user->roles)) {
  6. foreach($user->og_user_node['und'] as $key=>$values) {
  7. if(in_array($gid,$values)) {
  8. $get_user[] = $user;
  9. }
  10. }
  11. }
  12. }
  13. } if(isset($get_user)) {
  14. return $get_user;
  15. }else {
  16. return 0;
  17. }
  18. }