Same name and namespace in other branches
  1. 4.7.x modules/node.module \_node_access_where_sql()
  2. 5.x modules/node/node.module \_node_access_where_sql()
  3. 6.x modules/node/node.module \_node_access_where_sql()

Generate an SQL where clause for use in fetching a node listing.

Parameters

$op: The operation that must be allowed to return a node.

$node_access_alias: If the node_access table has been given an SQL alias other than the default "na", that must be passed here.

Return value

An SQL where clause.

Related topics

1 call to _node_access_where_sql()
node_db_rewrite_sql in modules/node.module
Implementation of hook_db_rewrite_sql

File

modules/node.module, line 1942
The core that allows content to be submitted to the site.

Code

function _node_access_where_sql($op = 'view', $node_access_alias = 'na', $uid = NULL) {
  if (user_access('administer nodes')) {
    return;
  }
  $sql = $node_access_alias . '.grant_' . $op . ' = 1 AND CONCAT(' . $node_access_alias . '.realm, ' . $node_access_alias . '.gid) IN (';
  $grants = array();
  foreach (node_access_grants($op, $uid) as $realm => $gids) {
    foreach ($gids as $gid) {
      $grants[] = "'" . $realm . $gid . "'";
    }
  }
  $sql .= implode(',', $grants) . ')';
  return $sql;
}