You are here

function nodeaccess_node_access_records in Nodeaccess 5

Same name and namespace in other branches
  1. 8.2 nodeaccess.module \nodeaccess_node_access_records()
  2. 8 nodeaccess.module \nodeaccess_node_access_records()
  3. 6.2 nodeaccess.module \nodeaccess_node_access_records()
  4. 6 nodeaccess.module \nodeaccess_node_access_records()
  5. 7 nodeaccess.module \nodeaccess_node_access_records()

Implementation of hook_node_access_records().

File

./nodeaccess.module, line 586

Code

function nodeaccess_node_access_records($node) {
  if (nodeaccess_disabling()) {
    return;
  }

  // Need to find out if node has own grants or whether to use defaults.
  $default = variable_get('nodeaccess_' . $node->type, array());

  // Load priority setting.
  $priority = variable_get('nodeaccess-priority', 0);
  $result = db_result(db_query("SELECT count(*) FROM {nodeaccess} WHERE nid = %d", $node->nid));
  if ($result < 1) {

    // Node has no own grants, use defaults.
    $grants = $default;
    foreach ($grants as $id => $grant) {
      $grants[$id]['priority'] = $priority;
    }
  }
  else {

    // Node has own grants, use them.
    $result = db_query("SELECT nid, gid, realm, grant_view, grant_update, grant_delete FROM {nodeaccess} WHERE nid = %d", $node->nid);
    $grants = array();
    while ($row = db_fetch_object($result)) {
      $grants[] = array(
        'gid' => $row->gid,
        'realm' => $row->realm,
        'grant_view' => $row->grant_view,
        'grant_update' => $row->grant_update,
        'grant_delete' => $row->grant_delete,
        'priority' => $priority,
      );
    }
  }

  // Apply author grants.
  $author_prefs = variable_get('nodeaccess_authors', array());

  // Array is prepopulated with grant values.
  $grant = $author_prefs[$node->type];
  $grant['gid'] = $node->uid;
  $grant['realm'] = 'nodeaccess_author';
  $grant['priority'] = $priority;

  // Include author grant even with all values false, it may be
  // needed to overwrite an older value.
  $grants[] = $grant;
  return $grants;
}