You are here

heartbeatmessagebuilder.inc in Heartbeat 6.3

Same filename and directory in other branches
  1. 6.4 includes/heartbeatmessagebuilder.inc

Strategy with access behaviour

@usage $context = new HeartbeatMessageBuilder(new PublicBehaviour()); $context->execute();

$context = new HeartbeatMessageBuilder(new PrivateBehaviour()); $context->execute();

$context = new HeartbeatMessageBuilder(new ConnectedBehaviour()); $context->execute();

File

includes/heartbeatmessagebuilder.inc
View source
<?php

/**
 * @file
 * Strategy with access behaviour
 *
 * @usage
 * $context = new HeartbeatMessageBuilder(new PublicBehaviour());
 * $context->execute();
 *
 * $context = new HeartbeatMessageBuilder(new PrivateBehaviour());
 * $context->execute();
 *
 * $context = new HeartbeatMessageBuilder(new ConnectedBehaviour());
 * $context->execute();
 *
 */

/**
 * Class HeartbeatMessageBuilder
 * Message builder that fetches and customizes a
 * users activity on the site.
 * The builder takes a heartbeataccess state object to
 * handle the request to fetch the messages.
 *
 */
class HeartbeatMessageBuilder {
  private $_heartbeatState = null;
  private $_hasErrors = FALSE;
  private $_errors = array();
  public function __construct(HeartbeatAccess $heartbeatState) {
    if (!$heartbeatState
      ->hasErrors()) {
      $this->_heartbeatState = $heartbeatState;
    }
    else {
      $this
        ->setError($heartbeatState
        ->getErrors());
    }
  }
  public function hasErrors() {
    return $this->_hasErrors;
  }
  protected function setError($errors) {
    $this->_errors = $errors;
    $this->_hasErrors = TRUE;
  }
  public function execute() {
    $heartbeat = $this->_heartbeatState
      ->fetchMessages();
    if (!empty($heartbeat->raw_messages)) {
      return $this
        ->group($heartbeat);
    }
    return array();
  }

  /**
   * @see class HeartbeatParser
   */
  public function group(HeartbeatParser $heartbeat) {
    $heartbeat
      ->set_timespan_gap(variable_get('heartbeat_activity_grouping_seconds', 720));
    $heartbeat
      ->build_sets($heartbeat->raw_messages);
    $heartbeat
      ->merge_sets();
    $messages = $heartbeat
      ->get_messages();

    //  $messages = $heartbeat->remove_broken_messages();
    return $messages;
  }

}

Classes

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