You are here

function domain_content_alter_node_query in Domain Access 7.2

Same name and namespace in other branches
  1. 7.3 domain_content/domain_content.admin.inc \domain_content_alter_node_query()

Abstraction to allow query alters outside of node access.

Parameters

$query: A dynamic node query.

$all_affiliates: Boolean value indicating whether to grant the 'domain_site' grant.

$current_domain: Boolean value indicating whether to grant the 'domain_id' grant.

1 call to domain_content_alter_node_query()
domain_content_form in domain_content/domain_content.admin.inc
Rewrites node_admin_nodes() to use db_rewrite_sql().

File

domain_content/domain_content.admin.inc, line 475
Administration pages for Domain Content.

Code

function domain_content_alter_node_query(QueryAlterableInterface $query, $all_affiliates = TRUE, $current_domain = TRUE) {
  $_domain = domain_get_domain();
  $domain_id = (int) $_domain['domain_id'];
  $tables = $query
    ->getTables();
  foreach ($tables as $nalias => $tableinfo) {
    $table = $tableinfo['table'];
    if (!$table instanceof SelectQueryInterface && $table == 'node') {
      $access_alias = $query
        ->join('domain_access', 'da_admin', "da_admin.nid = {$nalias}.nid");
      $or = db_or();
      if ($all_affiliates) {
        $or
          ->condition(db_and()
          ->condition("{$access_alias}.gid", 0)
          ->condition("{$access_alias}.realm", 'domain_site'));
      }
      if ($current_domain) {
        $or
          ->condition(db_and()
          ->condition("{$access_alias}.gid", $domain_id)
          ->condition("{$access_alias}.realm", 'domain_id'));
      }
      $query
        ->condition($or);

      // Node module will not have run, so add the distinct.
      $query
        ->distinct();
    }
  }
}