function simple_access_nodeapi in Simple Access 5
Same name and namespace in other branches
- 5.2 simple_access.module \simple_access_nodeapi()
- 6.2 simple_access.module \simple_access_nodeapi()
Implementation of hook_nodeapi()
File
- ./
simple_access.module, line 119 - This module allows administrators to make nodes viewable by specific 'access groups'. Each access group can contain any number of roles. If a node is not assigned to any access groups, it will remain viewable by all users.
Code
function simple_access_nodeapi(&$node, $op) {
switch ($op) {
case 'prepare':
if (!isset($node->simple_access)) {
$node->simple_access = array();
}
break;
case 'load':
$extra = array();
$result = db_query('SELECT na.gid, na.view, na.update, na.delete FROM {simple_access_node} na WHERE na.nid = %d', $node->nid);
while ($grant = db_fetch_array($result)) {
$gid = $grant['gid'];
unset($grant['gid']);
$extra[$gid] = $grant;
}
$node->simple_access = $extra;
break;
case 'update':
case 'insert':
db_query('DELETE FROM {simple_access_node} WHERE nid = %d', $node->nid);
if (isset($node->simple_access)) {
foreach ($node->simple_access as $gid => $access) {
if ($access['view'] || $access['update'] || $access['delete']) {
db_query("INSERT INTO {simple_access_node} (`nid`, `gid`, `view`, `update`, `delete`) VALUES (%d, %d, %d, %d, %d)", $node->nid, $gid, $access['view'], $access['update'], $access['delete']);
}
}
}
break;
case 'delete':
db_query('DELETE FROM {simple_access_node} WHERE nid = %d', $node->nid);
break;
}
}