You are here

function module_grants_get_node_access_realms in Module Grants 7

Get the realms and # of records in node_access table for a node or for access all

Parameters

$node:

Return value

array of record counts, keyed by realm.

1 call to module_grants_get_node_access_realms()
module_grants_get_node_access_realms_for_module in ./module_grants.module
Check if a module has node_access record for a node or for access all This is used in lenient mode, where if there's no node_access record from a module, then we skip the access checking for this module.
1 string reference to 'module_grants_get_node_access_realms'
module_grants_clear_node_access_cache in ./module_grants.module

File

./module_grants.module, line 497

Code

function module_grants_get_node_access_realms($node = NULL) {
  $node_access_realms =& drupal_static(__FUNCTION__);
  $nid = $node ? $node->nid : 0;
  if (!isset($node_access_realms[$nid])) {
    $query = db_select('node_access', 'na')
      ->fields('na', array(
      'realm',
    ));
    $query
      ->addExpression('COUNT(na.gid)', 'gid_count');
    if ($node) {
      $nid_condition = db_or()
        ->condition('na.nid', $node->nid)
        ->condition('na.nid', 0);
      $query
        ->condition($nid_condition);
    }
    $query
      ->groupBy('na.realm');
    $node_access_realms[$nid] = $query
      ->execute()
      ->fetchAllKeyed();
  }
  return $node_access_realms[$nid];
}