You are here

function _apachesolr_nodeaccess_build_subquery in Apache Solr Search 5

Same name and namespace in other branches
  1. 5.2 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:

2 calls to _apachesolr_nodeaccess_build_subquery()
apachesolr_nodeaccess_apachesolr_modify_query in contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module
Implementation of hook_apachesolr_modify_query().
DrupalApacheSolrNodeAccess::testQuery in contrib/apachesolr_nodeaccess/tests/apachesolr_nodeaccess.test

File

contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module, line 30

Code

function _apachesolr_nodeaccess_build_subquery($account) {
  if (!user_access('administer nodes', $account) && count(module_implements('node_grants'))) {

    // Get node access perms
    $node_access_query = "";
    $node_access_query = new Solr_Base_Query('', 'OR');
    $grants = node_access_grants('view', $account->uid);
    if (empty($grants)) {

      // If they can't see any content, we might as well not bother searching.
      // Catch the exception to null out the query.
      throw new Exception("This user cannot access any content!");
    }
    foreach ($grants as $realm => $gids) {
      foreach ($gids as $gid) {
        $node_access_query
          ->add_field('nodeaccess_' . $realm, $gid);
      }
    }
    return $node_access_query;
  }
  return NULL;
}