private function heartbeatParser::prepare_candidates in Heartbeat 7
Same name and namespace in other branches
- 6.4 includes/heartbeatparser.inc \heartbeatParser::prepare_candidates()
- 6.3 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 92 - HeartbeatParser object Parses database messages into a well formed stream of activity messages.
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 = $message->template->group_type;
// 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') {
// Skip if an identical activity message already exists.
/*if (isset($this->_messages[$gap_id]) && $message->uid == $this->_messages[$gap_id]->uid) {
continue;
}*/
// 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'],
'group_by_target' => isset($message->template->concat_args['group_by_target']) ? $message->template->concat_args['group_by_target'] : '',
'variables' => array(),
);
// Add the message
$this->_messages[$gap_id] = $message;
}
else {
$this->_messages[$gap_id]->timestamp = $message->timestamp;
}
// 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.
}
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++;
}
}
}