You are here

function heartbeat_example_nodeapi in Heartbeat 6.4

Implementation of hook_nodeapi().

File

modules/heartbeat_example/heartbeat_example.module, line 44

Code

function heartbeat_example_nodeapi(&$node, $op, $arg = 0) {

  // When a story is inserted, log user activity
  // Compare this approach with page. The latter works
  // with rules doing the same as this example.
  if ($op == 'insert' && $node->type == 'story') {
    $message_id = 'heartbeat_add_node';
    $variables = array(
      '@username' => l(heartbeat_user_load($node->uid)->name, 'user/' . $node->uid),
      '@node_type' => 'page',
      '@node_title' => l($node->title, 'node/' . $node->nid),
      // You could easily set the the time of the activity with
      // the time of node creation. (devel generate, imports, ...)
      'time' => $node->created,
    );
    heartbeat_api_log($message_id, $node->uid, 0, $node->nid, 0, $variables);
  }

  // When a page or story is updated, log activity for it.
  if ($op == 'update' && in_array($node->type, array(
    'page',
    'story',
  ))) {
    $message_id = 'heartbeat_edit_node';
    $variables = array(
      '@username' => l(heartbeat_user_load($node->uid)->name, 'user/' . $node->uid),
      '@node_type' => $node->type,
      '@nodetypes' => $node->type . '\'s',
      '@node_title' => l($node->title, 'node/' . $node->nid),
    );
    heartbeat_api_log($message_id, $node->uid, 0, $node->nid, 0, $variables);
  }
}