You are here

function _domain_store_grants in Domain Access 7.3

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

Store node_access records in the {domain_access} table.

Parameters

$nid: The node id being acted upon.

$grants: The grants passed by hook_node_access_records().

1 call to _domain_store_grants()
domain_node_access_records in ./domain.module
Implements hook_node_access_records().

File

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

Code

function _domain_store_grants($nid, $grants = array()) {

  // Store the grants records.
  if ($nid > 0 && !empty($grants)) {
    db_delete('domain_access')
      ->condition('nid', $nid)
      ->execute();
    $values = array();
    foreach ($grants as $grant) {

      // Always store unpublished nodes under domain_id.
      if ($grant['realm'] == 'domain_unpublished') {
        $grant['realm'] = 'domain_id';
      }
      $values[] = array(
        'nid' => $nid,
        'gid' => $grant['gid'],
        'realm' => $grant['realm'],
      );
    }
    $query = db_insert('domain_access')
      ->fields(array(
      'nid',
      'gid',
      'realm',
    ));
    foreach ($values as $record) {
      $query
        ->values($record);
    }
    $query
      ->execute();
  }

  // Reset the node-related domain static variables.
  drupal_static_reset('domain_get_node_domains');
  drupal_static_reset('domain_get_node_match');

  // Ensure that our default grant is present.
  domain_set_default_grant();
}