You are here

private function heartbeatParser::prepare_candidates in Heartbeat 6.3

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

Prepare message candidates This is an important method that handles several things

  • Build an id for each time-gap limiting groupable messages
  • Hold the candidates for each id (and count of messages)
  • Logic to handle the group_by node or user setting
1 call to heartbeatParser::prepare_candidates()
heartbeatParser::merge_sets in includes/heartbeatparser.inc
Merges sets of messages to fully formatted messages regenerated at runtime to group settings

File

includes/heartbeatparser.inc, line 150

Class

heartbeatParser

Code

private function prepare_candidates($message_set, $set_count = 0) {
  static $singles = 0;

  // Remove duplicate messages in the same set,
  // incrementing the counter on the grouped message
  $message_set = $this
    ->remove_message_duplicates($message_set);
  foreach ($message_set as $key => $message) {
    $type = $message->concat_args['type'];

    // 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;

    // Summaries have to be evaluated for merging
    if ($type == 'summary' && $this
      ->extend_gap_id($gap_id, $message, $type, $set_count)) {

      // Add a candidates if this one does not exist yet
      if (!isset($this->_candidates[$gap_id])) {
        $this->_candidates[$gap_id] = array(
          'count' => 0,
          'group_target' => $message->concat_args['group_target'],
          'variables' => array(),
        );

        // Add the message
        $this->_messages[$gap_id] = $message;
      }

      // Add the counters and variables needed for merging in groups
      $this->_messages[$gap_id]->target_count++;

      // Message occurrency, first time is 1
      $this->_candidates[$gap_id]['variables'][] = $message->variables_array;
      $this->_candidates[$gap_id]['count']++;

      // variable count, NOT the same as target_count
    }
    elseif ($type == 'count') {

      //$gap_id = $gap_id . '_'.$message->uid;
      $gap_id = $gap_id . '_count';
      $this->_messages[$gap_id] = $message;
      $this->_messages[$gap_id]->target_count++;
    }
    else {

      // Autoincrement the singles to make the gap_id unique
      $gap_id .= '_single_' . $singles;
      $this->_messages[$gap_id] = $message;
      $singles++;
    }
  }
}