private function heartbeatParser::prepare_candidates in Heartbeat 6.4
Same name and namespace in other branches
- 6.3 includes/heartbeatparser.inc \heartbeatParser::prepare_candidates()
- 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 115 - HeartbeatParser object
Class
- heartbeatParser
- 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) {
if (!$message->nid_access || !$message->nid_target_access || !$message->uid_access) {
continue;
}
$type = isset($message->template->concat_args['type']) ? $message->template->concat_args['type'] : 'single';
// Create a gap id, which is a unique id per time gap
$gap_id = $this
->create_gap_id($message, $type, $set_count);
// Summaries have to be evaluated for merging
if ($type == 'summary') {
// 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->template->concat_args['group_target'],
'variables' => array(),
);
// Add the message
$this->_messages[$gap_id] = $message;
$this->_messages[$gap_id]->additions->source = array(
$message->message . $message
->delete_button(),
);
}
else {
$this->_messages[$gap_id]->timestamp = $message->timestamp;
$this->_messages[$gap_id]->additions->source[] = $message->message . $message
->delete_button();
}
// 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;
$this->_candidates[$gap_id]['count']++;
// variable count, NOT the same as target_count
$this->_messages[$gap_id]->uaids[] = $message->uaid;
}
elseif ($type == 'count') {
$message_template = str_replace("%times%", $message->count, $message->message);
$message->message = str_replace("%count%", $message->count, $message_template);
$this->_messages[$gap_id] = $message;
}
else {
// Autoincrement the singles to make the gap_id unique
$gap_id .= '_' . $singles;
$this->_messages[$gap_id] = $message;
$singles++;
}
}
}