function simple_access_node_save in Simple Access 7.2
Same name and namespace in other branches
- 8.3 simple_access.module \simple_access_node_save()
Save node information.
2 calls to simple_access_node_save()
- simple_access_node_insert in ./
simple_access.module - Implements hook_node_insert().
- simple_access_node_update in ./
simple_access.module - Implements hook_node_update().
File
- ./
simple_access.module, line 222 - 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_node_save($node) {
if (isset($node->simple_access_owner)) {
$node->simple_access_owner += array(
'sa_view' => NULL,
'sa_update' => NULL,
'sa_delete' => NULL,
);
}
if ($node->uid && isset($node->simple_access_owner) && ($node->simple_access_owner['sa_view'] || $node->simple_access_owner['sa_update'] || $node->simple_access_owner['sa_update'])) {
db_merge('simple_access_owner')
->key(array(
'nid' => $node->nid,
))
->fields(array(
'sa_view' => $node->simple_access_owner['sa_view'],
'sa_update' => $node->simple_access_owner['sa_update'],
'sa_delete' => $node->simple_access_owner['sa_delete'],
))
->execute();
}
else {
db_delete('simple_access_owner')
->condition('nid', $node->nid)
->execute();
}
db_delete('simple_access_node')
->condition('nid', $node->nid)
->execute();
if (isset($node->simple_access)) {
foreach ($node->simple_access as $gid => $access) {
if ($access['sa_view'] || $access['sa_update'] || $access['sa_delete']) {
db_insert('simple_access_node')
->fields(array(
'nid' => $node->nid,
'gid' => $gid,
'sa_view' => $access['sa_view'],
'sa_update' => $access['sa_update'],
'sa_delete' => $access['sa_delete'],
))
->execute();
}
}
}
db_delete('simple_access_profiles_node')
->condition('nid', $node->nid)
->execute();
if (isset($node->simple_access_profiles)) {
foreach (array_filter($node->simple_access_profiles) as $pid) {
db_insert('simple_access_profiles_node')
->fields(array(
'nid' => $node->nid,
'pid' => $pid,
))
->execute();
}
}
}