You are here

function og_roles in Organic groups 7.2

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

Retrieve an array of roles matching specified conditions.

Parameters

$group_type: The group type.

$bundle: The bundle type.

$gid: The group ID.

$force_group: (optional) 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().

$include_all: (optional) If TRUE then the anonymous and authenticated default roles will be included.

Return value

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

45 calls to og_roles()
MigrateDestinationOGMembership::import in includes/migrate/plugins/destinations/og_membership.inc
Import a single membership.
OgAccess::testOgAccessEntity in ./og.test
Verify og_user_access_entity() returns correct value.
OgAccessModeratedGroup::setUp in og_access/og_access.test
Sets up a Drupal site for running functional and integration tests.
OgDefaultAccessFieldTestCase::testOgDefaultAccessField in ./og.test
Test groups with default access field enabled or disabled.
OgFieldAccessTestCase::testOgFieldAccess in og_field_access/og_field_access.test
Group with access field.

... See full list

1 string reference to 'og_roles'
og_ui_views_default_views in og_ui/includes/views/og_ui.views_default.inc
Implement hook_views_default_views().

File

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

Code

function og_roles($group_type, $bundle, $gid = 0, $force_group = FALSE, $include_all = TRUE) {
  if ($gid && !$bundle) {
    $wrapper = entity_metadata_wrapper($group_type, $gid);
    $bundle = $wrapper
      ->getBundle();
  }

  // Check if overriden access exists.
  if ($gid && !$force_group) {
    $query_gid = og_is_group_default_access($group_type, $gid) ? 0 : $gid;
  }
  else {
    $query_gid = $gid;
  }
  $query = db_select('og_role', 'ogr')
    ->fields('ogr', array(
    'rid',
    'name',
  ))
    ->condition('group_type', $group_type, '=')
    ->condition('group_bundle', $bundle, '=')
    ->condition('gid', $query_gid, '=')
    ->orderBy('rid', 'ASC');
  if (!$include_all) {
    $query
      ->condition('name', array(
      OG_ANONYMOUS_ROLE,
      OG_AUTHENTICATED_ROLE,
    ), 'NOT IN');
  }
  $rids = $query
    ->execute()
    ->fetchAllkeyed();
  return $rids;
}