You are here

function og_roles in Organic groups 7

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

Retrieve an array of roles matching specified conditions.

Parameters

$gid: The group node ID.

$permission: Optional; A string containing a permission. If set, only roles containing that permission are returned.

$force_group: Optioanl; If TRUE then the roles of the group will be retrieved by the group ID, even if the group is set to have default roles and permissions. The group might be set to "Default access" but infact there are inactive group roles. Thus, we are forcing the function to return the overriden roles. see og_delete_user_roles_by_group().

Return value

An associative array with the role id as the key and the role name as value. The anonymous and authenticated deault roles are on the top of the array.

15 calls to og_roles()
OgDefaultAccessFieldTestCase::testOgDefaultAccessField in ./og.test
Test groups with default access field enabled or disabled.
OgUiUpgradePathTestCase::testOgUiUpgrade in og_ui/og_ui.test
Test a successful upgrade.
og_delete_user_roles_by_group in ./og.module
Delete all roles belonging to a group.
og_get_global_roles in ./og.module
Get global roles - roles that belong to non-existent group ID 0.
og_get_user_roles in ./og.module
Get all roles of a user in a certain group.

... See full list

File

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

Code

function og_roles($gid = 0, $permission = NULL, $force_group = FALSE) {
  $roles = array();

  // Check if overriden access exists.
  if (!$force_group) {
    $gid = og_is_group_default_access($gid) ? 0 : $gid;
  }
  if (!empty($permission)) {
    $roles = db_query("SELECT r.rid, r.name FROM {og_role} r INNER JOIN {og_role_permission} p ON r.rid = p.rid WHERE p.permission = :permission AND r.gid = :gid ORDER BY r.name", array(
      ':permission' => $permission,
      ':gid' => $gid,
    ))
      ->fetchAllKeyed();
  }
  else {
    $roles = db_query("SELECT rid, name FROM {og_role} WHERE gid = :gid ORDER BY rid", array(
      ':gid' => $gid,
    ))
      ->fetchAllKeyed();
  }
  return $roles;
}