You are here

function _mongodb_session_get_roles in MongoDB 7

Obtain the roles for a user.

Parameters

object $account: A user account.

Return value

array The account roles, indexed by role ID.

File

mongodb_session/mongodb_session.module, line 39
MongoDB Session implementation.

Code

function _mongodb_session_get_roles($account) {
  $roles = array();
  $roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
  $result = db_query("SELECT r.rid, r.name, ur.uid FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid IN (:uids)", array(
    ':uids' => array(
      $account->uid,
    ),
  ));
  foreach ($result as $role) {
    $roles[(int) $role->rid] = $role->name;
  }
  return $roles;
}