You are here

function HeartbeatActivity::__construct in Heartbeat 7

Same name and namespace in other branches
  1. 6.4 includes/heartbeatactivity.inc \HeartbeatActivity::__construct()
  2. 6.3 includes/heartbeatactivity.inc \HeartbeatActivity::__construct()

constructor

Parameters

$data Array or Object with fields that can match this object: Data for the message, some are converted. It's possible to give a sql-result set as data which will adapt to a heartbeatActivity object.

$template HeartbeatMessageTemplate: holds the template data.

File

includes/heartbeatactivity.inc, line 69
HeartbeatActivity object Defines one heartbeat activity object.

Class

HeartbeatActivity
Class defines an activity message object

Code

function __construct($data, HeartbeatMessageTemplate $template) {

  //$this->_vars = new stdClass();
  $this->template = $template;
  $this->additions = new stdClass();
  $this->message_id = $this->template->message_id;
  if (is_object($data)) {
    $data = (array) $data;
  }
  if (isset($data['uaid'])) {
    $this->uaid = $data['uaid'];
  }
  if (isset($data['count'])) {
    $this->count = $data['count'];
  }
  $this->timestamp = isset($data['timestamp']) ? $data['timestamp'] : $_SERVER['REQUEST_TIME'];
  $this
    ->set_actor($data);
  if (isset($data['uid_target'])) {
    $this->uid_target = $data['uid_target'];
  }
  if (isset($data['nid'])) {
    $this->nid = $data['nid'];
  }
  if (isset($data['nid_target'])) {
    $this->nid_target = $data['nid_target'];
  }
  if (isset($data['cid'])) {
    $this->cid = $data['cid'];
  }
  if (isset($data['in_group'])) {
    $this->in_group = $data['in_group'];
  }
  if (isset($data['variables'])) {
    $this
      ->set_variables($data['variables']);
  }
  if (isset($data['extra']['duplicate'])) {
    $this->variables['duplicate'] = $data['extra']['duplicate'];
  }

  // Check access on the buttons and put their state onto the object
  $this
    ->set_delete_access();

  // Add buttons. Other modules can still add or remove buttons
  // using the available entity hooks.
  $this
    ->add_buttons();

  // Set the access for this message.
  $this
    ->setAccess($data);

  // Build the runtime activity message.
  $this
    ->rebuild_message();
  foreach ($data as $key => $value) {
    if (strpos($key, 'field_') === 0) {
      $this->{$key} = $value;
    }
  }
}