You are here

private function HeartbeatActivity::log_message in Heartbeat 7

Same name and namespace in other branches
  1. 6.4 includes/heartbeatactivity.inc \HeartbeatActivity::log_message()
  2. 6.3 includes/heartbeatactivity.inc \HeartbeatActivity::log_message()

Logs a heartbeat message

Parameters

string language optional:

1 call to HeartbeatActivity::log_message()
HeartbeatActivity::_save in includes/heartbeatactivity.inc
Save activity log

File

includes/heartbeatactivity.inc, line 486
HeartbeatActivity object Defines one heartbeat activity object.

Class

HeartbeatActivity
Class defines an activity message object

Code

private function log_message($args, $lang = '') {
  if (empty($lang)) {
    $lang = $GLOBALS['language']->language;
  }

  // Checks if there should be logging what so ever.
  if (empty($this->message)) {
    watchdog('heartbeat', 'Error in logging user activity: it is not possible to log empty message', array(), WATCHDOG_ERROR);
    return FALSE;
  }

  // Rewrite access if the user has configured the access state of this message type.
  $heartbeat_user_templates = heartbeat_user_templates_load($this->uid);
  if (!empty($heartbeat_user_templates) && isset($heartbeat_user_templates[$this->message_id])) {
    $this->access = $heartbeat_user_templates[$this->message_id]->status;
  }

  // Prepare extra variables (hardcoded for node for now)
  // TODO think of a cleaner sollution.
  if ($this->nid > 0 && ($node = node_load($this->nid))) {
    $this->variables['node_type'] = $node->type;
    $this->variables['node_status'] = $node->status;
    $this->variables['node_uid'] = $node->uid;
  }
  if ($this->nid_target > 0 && ($node = node_load($this->nid_target))) {
    $this->variables['node_target_type'] = $node->type;
    $this->variables['node_target_status'] = $node->status;
    $this->variables['node_target_uid'] = $node->uid;
  }

  // Log relational message to user activity
  $last_id = db_insert('heartbeat_activity')
    ->fields(array(
    'message_id',
    'nid',
    'uid',
    'nid_target',
    'uid_target',
    'cid',
    'access',
    'timestamp',
    'language',
    'variables',
    'in_group',
  ))
    ->values(array(
    'message_id' => $this->message_id,
    'nid' => $this->nid,
    'uid' => $this->uid,
    'nid_target' => $this->nid_target,
    'uid_target' => $this->uid_target,
    'cid' => $this->cid,
    'access' => $this->access,
    'timestamp' => $this->timestamp,
    'language' => $lang,
    'in_group' => $this->in_group,
    'variables' => heartbeat_encode_message_variables($this->variables),
  ))
    ->execute();

  // Add the uaid.
  $this->uaid = $last_id;

  // Allow modules to respond to the save of a heartbeat activity message.
  module_invoke_all('heartbeat_activity_save', $this);
  return $last_id ? $last_id : 0;
}