You are here

function grants_by_module in Module Grants 6

Return a map keyed by module name of SQL clauses representing the grants associated with the module, as returned by that module's hook_node_grants().

Parameters

$op: The operation, i.e 'view', 'update' or 'delete'

$account: User account object

Return value

Array of module grants SQL

1 call to grants_by_module()
module_grants_node_access in ./module_grants.module
Similar to node_access() in node.module but ANDs rather than ORs grants together on a per module base to create more natural behaviour. Also makes sure that published and unpublished content are treated in the same way, i.e. that grants are checked in…

File

./module_grants.module, line 206
Module to enable access control for unpublished content. Also makes sure that modules that operate on access grants behave in the expected way when enabled together.

Code

function grants_by_module($op, $account) {
  $hook = 'node_grants';
  $all_grants = array();
  foreach (module_implements($hook) as $module) {
    $module_grants = array();
    foreach (module_invoke($module, $hook, $account, $op) as $realm => $gids) {
      foreach ($gids as $gid) {
        $module_grants[] = "(gid={$gid} AND realm='{$realm}')";
      }
    }

    // Within a module OR the gid/realm combinations together
    $module_sql = implode(' OR ', $module_grants);
    $all_grants[$module] = $module_sql;
  }
  return $all_grants;
}