You are here

function domain_get_node_domains in Domain Access 6.2

Same name and namespace in other branches
  1. 7.3 domain.module \domain_get_node_domains()
  2. 7.2 domain.module \domain_get_node_domains()

Get the domains for a node.

Parameters

$nid: The node id.

$reset: A boolean flag indicating the need to reset the static variable for the node.

$return: Used with reset. Indicates that a new lookup should be run and the result returned. @see _domain_store_grants()

Return value

An array, consisting of two parts. 'domain_id' is an array of active domain ids. 'domain_site' is a TRUE/FALSE boolean indicating affiliate status.

4 calls to domain_get_node_domains()
domain_content_update_nodes in domain_content/domain_content.module
Abstraction function that lets us update access rules.
domain_nodeapi in ./domain.module
Implement hook_nodeapi().
domain_source_lookup in domain_source/domain_source.module
Find the proper source domain for a node.
_domain_store_grants in ./domain.module
Store node_access records in the {domain_access} table.

File

./domain.module, line 1536
Core module functions for the Domain Access suite.

Code

function domain_get_node_domains($nid, $reset = FALSE, $return = FALSE) {
  static $lookup = array();
  if (isset($lookup[$nid])) {

    // If set and valid, return.
    if (empty($reset)) {
      return $lookup[$nid];
    }
    else {
      if (empty($return)) {
        unset($lookup[$nid]);
        return;
      }
    }
  }

  // Set the proper value for the node.
  $domains = array(
    'domain_id' => array(),
    'domain_site' => FALSE,
  );
  $result = db_query("SELECT gid, realm FROM {domain_access} WHERE nid = %d AND (realm = '%s' OR realm = '%s')", $nid, 'domain_id', 'domain_site');
  while ($data = db_fetch_object($result)) {

    // Transform the 0 to -1, since {domain_access} is unsigned.
    $data->gid == 0 ? $gid = -1 : ($gid = $data->gid);
    if ($data->realm == 'domain_id') {
      $domains['domain_id'][$gid] = $gid;
    }
    else {
      if ($data->realm == 'domain_site') {
        $domains['domain_site'] = TRUE;
      }
    }
  }
  $lookup[$nid] = $domains;
  return $lookup[$nid];
}