You are here

function feeds_tests_query_term_access_alter in Feeds 7.2

Implements hook_query_TAG_alter() for tag 'term_access'.

File

tests/feeds_tests.module, line 322
Helper module for Feeds tests.

Code

function feeds_tests_query_term_access_alter(QueryAlterableInterface $query) {
  global $user;
  $allowed_user = variable_get('feeds_tests_term_reference_allowed_user', NULL);
  if (is_null($allowed_user)) {

    // No allowed user set. Abort.
    return;
  }

  // Read meta-data from query, if provided.
  if (!($account = $query
    ->getMetaData('account'))) {
    $account = $user;
  }

  // If the current active user is the set user, abort.
  if ($account->uid == $allowed_user) {
    return;
  }

  // If $account can bypass node access, or there are no node access
  // modules, we don't need to alter the query.
  if (user_access('bypass node access', $account)) {
    return;
  }

  // Disallow any terms.
  $tables = $query
    ->getTables();
  foreach ($tables as $talias => $tableinfo) {
    $table = $tableinfo['table'];
    if (!$table instanceof SelectQueryInterface && $table == 'taxonomy_term_data') {
      $query
        ->condition("{$talias}.tid", 0);
    }
  }
}