You are here

function sbp_test_nodeapi in Search by Page 6

Implementation of hook_nodeapi().

Manage the "private" flag on nodes. Code taken form the Node Access Example module on drupal.org.

File

tests/sbp_test.module, line 124
Module file for Search by Page testing.

Code

function sbp_test_nodeapi(&$node, $op, $arg = 0) {
  switch ($op) {
    case 'load':
      $result = db_fetch_object(db_query('SELECT * FROM {sbp_test_access} WHERE nid = %d', $node->nid));
      $node->test_private = $result->private;
      break;
    case 'delete':
      db_query('DELETE FROM {sbp_test_access} WHERE nid = %d', $node->nid);
      break;
    case 'insert':
      if (!isset($node->test_private)) {
        $node->test_private = FALSE;
      }
      db_query('INSERT INTO {sbp_test_access} (nid, private) VALUES (%d, %d)', $node->nid, $node->test_private);
      break;
    case 'update':
      if (!isset($node->test_private)) {
        $node->test_private = FALSE;
      }
      db_query('UPDATE {sbp_test_access} SET private = %d WHERE nid = %d', $node->test_private, $node->nid);
      break;
  }
}