function vppn_node_access in View Permission Per Node 7
Implements hook_node_access().
File
- ./
vppn.module, line 183 - Configuration for VPPN.
Code
function vppn_node_access($node, $op, $account) {
// Only concerned with viewing.
if ($op != 'view') {
// Ignore if any other op.
return NODE_ACCESS_IGNORE;
}
// Make sure there's a node id.
if (empty($node->nid)) {
// Should never happen but ignore if no nid.
return NODE_ACCESS_IGNORE;
}
// Check if it's a valid VPPN content type.
if (empty($node->type) || !variable_get('vppn_node_' . $node->type, 0)) {
// Not a VPPN node type, we don't care.
return NODE_ACCESS_IGNORE;
}
// Get the records for this node.
$records = db_select('vppn')
->fields('vppn', array(
'rid',
))
->condition('nid', $node->nid)
->execute();
// Check that there is a record for this node.
if (!$records
->rowCount()) {
// No record.
return NODE_ACCESS_IGNORE;
}
// Get the roles that can view this node.
$allowed_roles = array_flip($records
->fetchCol());
// Make sure the user has one of the allowed roles.
return count(array_intersect_key($allowed_roles, $account->roles)) ? NODE_ACCESS_ALLOW : NODE_ACCESS_DENY;
}