You are here

function og_role_permissions in Organic groups 7.2

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

Determine the permissions for one or more roles.

Parameters

$roles: An array whose keys are the role IDs of interest.

Return value

An array indexed by role ID. Each value is an array whose keys are the permission strings for the given role ID.

8 calls to og_role_permissions()
OgMigrateRoles::preImport in includes/migrate/7200/og_roles.migrate.inc
Copy all existing global roles to bundle-specific versions. Although similar processing is available through the og_roles_override() function, special handling is necessary to ensure that custom global roles are copied as well as default global roles.
OgUiMigrate7000TestCase::testUpgrade in og_ui/og_ui.test
Test a successful upgrade.
OgUiSetRoles::prepareRow in og_ui/includes/migrate/7000/set_roles.inc
Default implementation of prepareRow(). This method is called from the source plugin upon first pulling the raw data from the source.
og_handler_field_group_permissions::pre_render in includes/views/handlers/og_handler_field_group_permissions.inc
Run before any fields are rendered.
og_register_og_membership_state_validate in og_register/og_register.module
Validate handler; Set the state according to the "subscribe" permissions of the group.

... See full list

1 string reference to 'og_role_permissions'
og_invalidate_cache in ./og.module
Invalidate cache.

File

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

Code

function og_role_permissions($roles = array()) {
  $cache =& drupal_static(__FUNCTION__, array());
  $role_permissions = $fetch = array();
  if ($roles) {
    foreach ($roles as $rid => $name) {
      if (isset($cache[$rid])) {
        $role_permissions[$rid] = $cache[$rid];
      }
      else {

        // Add this rid to the list of those needing to be fetched.
        $fetch[] = $rid;

        // Prepare in case no permissions are returned.
        $cache[$rid] = array();
      }
    }
    if ($fetch) {

      // Get from the database permissions that were not in the static variable.
      // Only role IDs with at least one permission assigned will return rows.
      $result = db_query("SELECT rid, permission FROM {og_role_permission} WHERE rid IN (:fetch)", array(
        ':fetch' => $fetch,
      ));
      foreach ($result as $row) {
        $cache[$row->rid][$row->permission] = TRUE;
      }
      foreach ($fetch as $rid) {

        // For every rid, we know we at least assigned an empty array.
        $role_permissions[$rid] = $cache[$rid];
      }
    }
  }
  return $role_permissions;
}