You are here

function heartbeat_api_log in Heartbeat 7

Same name and namespace in other branches
  1. 6.4 heartbeat.module \heartbeat_api_log()
  2. 6.3 heartbeat.module \heartbeat_api_log()

API function to log a message from custom code

Parameters

string $message_id: Id of the message that is known in the message

integer $uid: Actor or user performing the activity

integer $uid_target [optional]: user id of the target user if present. Target users can be an addresse or a user relation transaction with the actor $uid

integer $nid [optional]: Node id for content (for context node)

integer $nid_target [optional]: Node id for content that is related to other content

array $variables [optional]: Variables can be used if you used them in the used message. Take care to use the @-sign for words that are prefix with the question mark sign in the messages

integer $access: The access to restrict the message

2 calls to heartbeat_api_log()
heartbeat_example_node_insert in modules/heartbeat_example/heartbeat_example.module
Implements hook_node_insert().
heartbeat_example_node_update in modules/heartbeat_example/heartbeat_example.module
Implements hook_node_update().

File

./heartbeat.module, line 855
Module file for heartbeat activity. Basic hook implementations and helper functions will be found here.

Code

function heartbeat_api_log($message_id, $uid, $uid_target = 0, $nid = 0, $nid_target = 0, $variables = array(), $access = NULL, $time = 0, $in_group = 0) {
  $template = heartbeat_message_template_load($message_id);

  // Access can be given but usually we calculate it from Template Permissions
  // and overridable with the setting of the user.
  if (!isset($access) || !is_numeric($access)) {
    $access = _heartbeat_activity_get_access($uid, $template);
  }
  $data = array();

  // Normal form values
  $data['message_id'] = $message_id;
  $data['uid'] = $uid;
  $data['uid_target'] = $uid_target;
  $data['nid'] = $nid;
  $data['nid_target'] = $nid_target;
  $data['cid'] = isset($variables['cid']) ? $variables['cid'] : 0;
  $data['access'] = $access;
  $data['in_group'] = $in_group;
  $data['timestamp'] = $time == 0 ? $_SERVER['REQUEST_TIME'] : $time;
  $data['variables'] = $variables;
  return heartbeat_log($data);
}