You are here

function workbench_access_node_load in Workbench Access 7

Implements hook_node_load().

1 string reference to 'workbench_access_node_load'
workbench_access_reset_tree in ./workbench_access.module
Reset tree data stored in statics.

File

./workbench_access.module, line 595
Workbench Access module file.

Code

function workbench_access_node_load($nodes, $types) {
  $scheme =& drupal_static(__FUNCTION__);
  if (!isset($scheme)) {
    $scheme = variable_get('workbench_access');
  }
  $tree = workbench_access_get_active_tree();
  $result = array();
  if (!empty($tree['active']) && !empty($nodes)) {
    $result = db_query("SELECT nid, access_id FROM {workbench_access_node} WHERE nid IN (:nid) AND access_scheme = :access_scheme", array(
      ':nid' => array_keys($nodes),
      ':access_scheme' => $scheme,
    ))
      ->fetchAll();
  }
  $data = array();
  foreach ($result as $obj) {
    $data[$obj->nid][$obj->access_id] = $obj->access_id;
  }
  foreach ($nodes as $node) {

    // Cannot load if the node has not been created yet or if it is
    // not under access control.
    if (empty($node->nid) || isset($node->type) && !variable_get('workbench_access_node_type_' . $node->type, 1)) {
      continue;
    }
    $nodes[$node->nid]->workbench_access = array();
    if (empty($data[$node->nid])) {
      continue;
    }
    foreach ($data[$node->nid] as $access_id) {
      if (in_array($access_id, array_keys($tree['active']))) {
        $nodes[$node->nid]->workbench_access[$access_id] = $access_id;
      }
    }
  }
}