You are here

function views_plugin_row_heartbeat_view::init in Heartbeat 6.3

Same name and namespace in other branches
  1. 7 views/views_plugin_row_heartbeat_view.inc \views_plugin_row_heartbeat_view::init()

File

views/plugins/views_plugin_row_heartbeat_view.inc, line 14
Contains the heartbeat row style plugin.

Class

views_plugin_row_heartbeat_view
Plugin which performs a heartbeat_view on the resulting object.

Code

function init(&$view, &$display, $options = NULL) {

  // call init of base class
  parent::init($view, $display, $options);
  if ($view->query === null || !method_exists($view->query, 'add_field')) {

    //drupal_set_message('Something went wrong while fetching heartbeat messages.', 'error');
    return;
  }
  $table1 = 'heartbeat_activity';
  $table2 = 'heartbeat_messages';
  $join_by = 'message_id';

  // Clear the fields first

  //$view->query->clear_fields();

  // Build the fields for heartbeat_activity
  $fields = _heartbeat_get_fields($table1);
  foreach ($fields as $field => $alias) {
    $view->query
      ->add_field($table1, $field, $alias);
  }

  // Build the fields for heartbeat_messages
  $join = new views_join();
  $join
    ->construct($table2, $table1, $join_by, $join_by);
  $view->query
    ->add_relationship($table2, $join, $table1);

  //$view->query->add_table($table2);
  $fields = _heartbeat_get_fields($table2);
  foreach ($fields as $field => $alias) {
    $view->query
      ->add_field($table2, $field, $alias);
  }
}