You are here

function acl_node_access_records in ACL 7

Same name and namespace in other branches
  1. 8 acl.module \acl_node_access_records()
  2. 5 acl.module \acl_node_access_records()
  3. 6 acl.module \acl_node_access_records()

Implements hook_node_access_records().

File

./acl.module, line 267
An API module providing by-user access control lists.

Code

function acl_node_access_records($node) {
  if (!$node->nid) {
    return;
  }
  $result = db_query("SELECT n.*, 'acl' AS realm, n.acl_id AS gid, a.module FROM {acl_node} n INNER JOIN {acl} a ON n.acl_id = a.acl_id WHERE nid = :nid", array(
    'nid' => $node->nid,
  ), array(
    'fetch' => PDO::FETCH_ASSOC,
  ));
  $grants = array();
  foreach ($result as $grant) {
    if (module_invoke($grant['module'], 'enabled')) {
      if (acl_has_users($grant['gid'])) {
        $grants[] = $grant;
      }
      else {

        //just deny access
        $grants[] = array(
          'realm' => 'acl',
          'gid' => $grant['gid'],
          'grant_view' => 0,
          'grant_update' => 0,
          'grant_delete' => 0,
          'priority' => $grant['priority'],
        );
      }
    }
  }
  return $grants;
}