You are here

function og_get_user_roles in Organic groups 7

Same name and namespace in other branches
  1. 7.2 og.module \og_get_user_roles()

Get all roles of a user in a certain group.

Parameters

$gid: The group ID.

$uid: The user ID.

$include: Optional; If TRUE also anonymous or authenticated role ID will be returned. Defaults to TRUE.

Return value

Array with the role IDs of the user.

8 calls to og_get_user_roles()
OgMigrate7000TestCase::testogMigrateUpgradeUsers in og_migrate/og_migrate.test
og_handler_field_group_permissions::pre_render in includes/views/og_handler_field_group_permissions.inc
Run before any fields are rendered.
og_handler_field_user_roles::pre_render in includes/views/og_handler_field_user_roles.inc
Run before any fields are rendered.
og_role_grant in ./og.module
Grant a group role to a user.
og_role_revoke in ./og.module
Revoke a group role from a user.

... See full list

File

./og.module, line 2540
Enable users to create and manage groups with roles and permissions.

Code

function og_get_user_roles($gid, $uid = NULL, $include = TRUE) {
  $roles = array();
  if (empty($uid)) {
    global $user;
    $uid = $user->uid;
  }
  if ($include) {

    // Check if overriden access exists.
    $query_gid = og_is_group_default_access($gid) ? 0 : $gid;
    $group_roles = og_roles($query_gid);
    $account = user_load($uid);
    $name = og_is_member($gid, 'user', $account) ? OG_AUTHENTICATED_ROLE : OG_ANONYMOUS_ROLE;
    $rid = array_search($name, $group_roles);
    $roles[$rid] = $rid;
  }
  $roles = $roles + db_query("SELECT rid, rid FROM {og_users_roles} WHERE uid = :uid AND gid = :gid", array(
    ':uid' => $uid,
    ':gid' => $gid,
  ))
    ->fetchAllKeyed();
  return $roles;
}