You are here

function forum_access_node_access_records in Forum Access 6

Same name and namespace in other branches
  1. 8 forum_access.module \forum_access_node_access_records()
  2. 5 forum_access.module \forum_access_node_access_records()
  3. 7 forum_access.module \forum_access_node_access_records()

Implementation of hook_node_access_records().

Returns a list of grant records for the passed in node object. Checks to see if maybe we're being disabled.

File

./forum_access.module, line 28
forum_access.module

Code

function forum_access_node_access_records($node) {
  if (!forum_access_enabled()) {
    return;
  }
  static $grants = array();
  static $node_admins;
  $tid = _forum_access_get_tid($node);

  // Set proper grants for nodecomment comment nodes.
  if (isset($node->comment_target_nid)) {
    if ($changed_tid = _forum_access_changed_tid()) {
      $tid = $changed_tid;

      // the topic node hasn't been saved yet!
    }
    else {
      $node = node_load($node->comment_target_nid);
      $tid = _forum_access_get_tid($node);
    }
  }
  if ($tid) {
    if (!isset($grants[$tid])) {
      if (!isset($node_admins)) {
        $node_admins = user_roles(FALSE, 'administer nodes');
      }
      $result = db_query('SELECT * FROM {forum_access} WHERE tid = %d', $tid);
      while ($grant = db_fetch_object($result)) {
        if (isset($node_admins[$grant->rid])) {
          continue;

          // Don't provide any useless grants!
        }
        $grants[$tid][] = array(
          'realm' => 'forum_access',
          'gid' => $grant->rid,
          'grant_view' => $grant->grant_view,
          'grant_update' => $grant->grant_update,
          'grant_delete' => $grant->grant_delete,
          'priority' => $grant->priority,
        );
      }

      //drupal_set_message("forum_access_node_access_records($node->nid) (tid=$tid) returns ". var_export($grants[$tid], TRUE), 'status');
    }
    if (isset($grants[$tid])) {
      return $grants[$tid];
    }
  }
}