You are here

function apachesolr_access_build_subquery in Apache Solr Search 6.3

Same name and namespace in other branches
  1. 8 apachesolr_access/apachesolr_access.module \apachesolr_access_build_subquery()
  2. 7 apachesolr_access/apachesolr_access.module \apachesolr_access_build_subquery()

Creates a Solr query for a given user

Parameters

$account an account to get grants for and build a solr query:

Throws

Exception

2 calls to apachesolr_access_build_subquery()
apachesolr_access_apachesolr_query_alter in apachesolr_access/apachesolr_access.module
Implements hook_apachesolr_query_alter().
DrupalApacheSolrNodeAccess::testIndexing in apachesolr_access/tests/apachesolr_access.test

File

apachesolr_access/apachesolr_access.module, line 39

Code

function apachesolr_access_build_subquery($account) {
  if (!user_access('access content', $account)) {
    throw new Exception('No access');
  }
  $node_access_query = apachesolr_drupal_subquery();
  if (user_access('administer nodes', $account)) {

    // Access all content from the current site, or public content.
    $node_access_query
      ->addFilter('access__all', 0);
    $node_access_query
      ->addFilter('hash', apachesolr_site_hash());
  }
  else {

    // Get node access grants.
    $grants = node_access_grants('view', $account);
    foreach ($grants as $realm => $gids) {
      $realm = apachesolr_access_clean_realm_name($realm);
      foreach ($gids as $gid) {
        $node_access_query
          ->addFilter('access_node_' . apachesolr_site_hash() . '_' . $realm, $gid);
      }
    }
    $node_access_query
      ->addFilter('access__all', 0);
  }
  return $node_access_query;
}