You are here

function og_role_grant in Organic groups 7.2

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

Grant a group role to a user.

Parameters

$group_type: The entity type of the group.

$gid: The group ID.

$uid: The user ID.

$rid: The role ID.

11 calls to og_role_grant()
MigrateDestinationOGMembership::import in includes/migrate/plugins/destinations/og_membership.inc
Import a single membership.
OgDefaultAccessFieldTestCase::testOgDefaultAccessField in ./og.test
Test groups with default access field enabled or disabled.
OgPermissionsTestCase::testBlockedAndPendingRoles in ./og.test
Assert blocked and pending roles influence the allowed permissions.
OgPermissionsTestCase::testGrantRolesTwiceForPendingUsers in ./og.test
OgRoleRevoke::testOgRoleRevoke in ./og.test

... See full list

File

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

Code

function og_role_grant($group_type, $gid, $uid, $rid) {

  // Make sure the role is valid.
  $group = entity_load_single($group_type, $gid);
  list(, , $bundle) = entity_extract_ids($group_type, $group);
  $og_roles = og_roles($group_type, $bundle, $gid, FALSE, FALSE);
  if (empty($og_roles[$rid])) {

    // Role isn't valid.
    return;
  }

  // Get the existing user roles.
  $user_roles = og_get_user_roles($group_type, $gid, $uid, TRUE, FALSE);
  if (empty($user_roles[$rid])) {
    $role = new stdClass();
    $role->uid = $uid;
    $role->rid = $rid;
    $role->group_type = $group_type;
    $role->gid = $gid;
    drupal_write_record('og_users_roles', $role);
    og_invalidate_cache();
    module_invoke_all('og_role_grant', $group_type, $gid, $uid, $rid);
    if (module_exists('rules')) {
      rules_invoke_event('og_role_grant', og_get_membership($group_type, $gid, 'user', $uid), entity_metadata_wrapper('user', $uid), $rid);
    }
  }
}