You are here

function apps_app_configure_og_permissions in Apps 7

Set the permission for a role for og.

Parameters

$app: A fully loaded app object.

2 calls to apps_app_configure_og_permissions()
apps_update_7102 in ./apps.install
Reset permissions
og_apps_app_modules_enabled in ./apps.module
Implements hook_apps_app_modules_enabled().

File

./apps.module, line 728
Module file for Apps

Code

function apps_app_configure_og_permissions($app) {
  node_types_rebuild();
  module_load_include('inc', 'og', 'includes/og_features_role.features');
  if (!empty($app['og permissions'])) {
    foreach ($app['og permissions'] as $key => $roles) {
      list($group_type, $bundle, $perm) = explode(':', $key);

      // Make sure the role exists for this entity.
      foreach ($roles as $role) {
        $bundle_role = _og_features_role_exists($role, $group_type, $bundle);
        if (empty($bundle_role)) {
          og_role_save(og_role_create($role, $group_type, 0, $bundle));
        }
      }
      $all_roles = og_roles($group_type, $bundle, 0);
      foreach ($all_roles as $rid => $rolename) {
        if (in_array($rolename, $roles)) {
          $grant[$rid][] = $perm;
        }
        else {
          $revoke[$rid][] = $perm;
        }
      }
    }
    if (!empty($grant)) {
      foreach ($grant as $rid => $permissions) {
        og_role_grant_permissions($rid, $permissions);
      }
    }
    if (!empty($revoke)) {
      foreach ($revoke as $rid => $permissions) {
        og_role_revoke_permissions($rid, $permissions);
      }
    }
  }
}