You are here

function _apachesolr_nodeaccess_build_subquery in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 5 contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module \_apachesolr_nodeaccess_build_subquery()
  2. 6 contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module \_apachesolr_nodeaccess_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

1 call to _apachesolr_nodeaccess_build_subquery()
apachesolr_nodeaccess_apachesolr_modify_query in contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module
Implementation of hook_apachesolr_modify_query().

File

contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module, line 51

Code

function _apachesolr_nodeaccess_build_subquery($account) {
  if (!user_access('access content', $account)) {
    throw new Exception('No access');
  }
  $node_access_query = apachesolr_drupal_query();
  if (empty($node_access_query)) {
    throw new Exception('No query object in apachesolr_nodeaccess');
  }
  if (user_access('administer nodes', $account)) {

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

    // Get node access grants.
    $grants = node_access_grants('view', $account->uid);
    foreach ($grants as $realm => $gids) {
      foreach ($gids as $gid) {
        $node_access_query
          ->add_filter('nodeaccess_' . apachesolr_site_hash() . '_' . $realm, $gid);
      }
    }
    $node_access_query
      ->add_filter('nodeaccess_all', 0);
  }
  return $node_access_query;
}