You are here

private function heartbeatParser::create_gap_id in Heartbeat 7

Same name and namespace in other branches
  1. 6.4 includes/heartbeatparser.inc \heartbeatParser::create_gap_id()

create_gap_id Private helper function to build the gap_id

Parameters

Object HeartbeatActivity $message: Object that holds the data of a heartbeat stream message

String $type: type of the HeartbeatActivity message

integer $set_count: The count id of the current timespan where data must be grouped

Return value

$gap_id A unique id to summarize data within a certain timespan

1 call to heartbeatParser::create_gap_id()
heartbeatParser::prepare_candidates in includes/heartbeatparser.inc
Prepare message candidates This is an important method that handles several things

File

includes/heartbeatparser.inc, line 230
HeartbeatParser object Parses database messages into a well formed stream of activity messages.

Class

heartbeatParser
Class heartbeatParser

Code

private function create_gap_id($message, $type, $set_count) {

  // Variable to hold the unique grouping gap id.
  // Extending the gap id will result in summaries
  // and groups of identical and related messages.
  $gap_id = 'BEAT_' . $set_count . '_' . $message->message_id;

  // Extend the gap id with the node_type if available
  // but this is too dangerous because i don't know if people intend to
  // separate the node types from merging ...
  if (!empty($message->variables['node_type'])) {
    $gap_id .= '_' . $message->variables['node_type'];
  }

  // For single types, we dont need larger unique id's
  if ($type == 'single') {
    return $gap_id . '_single';
  }
  elseif ($type == 'count') {
    return $gap_id . '_count' . $message->uid;
  }

  // Summary.
  // Merge messages by splitting up activity instances within timespans.
  $grouptarget = $message->template->concat_args['group_target'];
  $groupby = $message->template->concat_args['group_by'];

  // group by node will result in a summary of
  // users performing the activity
  if ($groupby == 'node') {
    $gap_id .= '_' . $grouptarget . '_node_' . $message->nid;
  }
  elseif ($groupby == 'user') {
    $gap_id .= '_' . $grouptarget . '_user_' . $message->uid;
    if ($message->nid_target > 0) {
      $gap_id .= '_' . $message->nid_target;
    }
  }
  elseif ($groupby == 'node-target') {
    $gap_id .= '_' . $grouptarget . '_user_' . $message->uid . '_node_target_' . $message->nid_target;
  }
  elseif ($groupby == 'user-user') {
    $gap_id .= '_user_relation';

    //$gap_id .= '_'. ($target_uid == 0 ? $message->uid : $target_uid);
    $group_target = $message->template->concat_args['group_by_target'];
    $string = $message->variables['!' . $group_target];
    $group_gap_string = strip_tags(drupal_strtolower($string));
    $gap_id .= '_' . $group_gap_string;
  }
  else {

    // Handle the fall-backs as unique messages
    $gap_id .= '_' . $message->uid . '_' . (int) $message->uid_target;
  }
  return $gap_id;
}