You are here

public function HeartbeatMessageBuilder::execute in Heartbeat 6.4

Same name and namespace in other branches
  1. 6.3 includes/heartbeatmessagebuilder.inc \HeartbeatMessageBuilder::execute()

Executes a query, putting the result into a wellformed stream of heartbeat activity objects

Return value

$messages array of messages

File

includes/heartbeatmessagebuilder.inc, line 87
Strategy with access behaviour

Class

HeartbeatMessageBuilder
Class HeartbeatMessageBuilder Message builder that fetches and customizes users activity on the site. The builder takes a heartbeataccess object to handle the request to fetch the messages.

Code

public function execute() {

  // Fetch the messages from database for current State
  $heartbeat = $this->_heartbeatState
    ->fetchMessages();
  if (!empty($heartbeat->raw_messages)) {

    // Filter messages by permission
    $this
      ->checkAccess($heartbeat);

    // Group the activity messages as configured
    $messages = $this
      ->group($heartbeat);
  }
  if (!empty($messages)) {

    // Give contributes modules the opportunity to load
    // additions for the heartbeat activity message object
    $hook = 'heartbeat_load';
    foreach (module_implements($hook) as $module) {
      $function = $module . '_' . $hook;

      // $messages should be implemented by reference!!!
      $function($messages, $this->_heartbeatState);
    }

    // Let other modules retheme or completely rebuild messages
    $hook = 'heartbeat_theme_alter';
    foreach (module_implements($hook) as $module) {
      $function = $module . '_' . $hook;
      $result = $function($messages, $this->_heartbeatState);
    }

    // Give contributes modules the last chance to hook into the messages
    $hook = 'heartbeat_view';
    foreach (module_implements($hook) as $module) {
      $function = $module . '_' . $hook;

      // $messages should be implemented by reference!!!
      $function($messages, $this->_heartbeatState);
    }
    return $messages;
  }
  return array();
}