You are here

function heartbeat_views_views_query_alter in Heartbeat 6.4

Implementation of hook_views_query_alter().

File

views/heartbeat_views.views.inc, line 240
Views integration for heartbeat.

Code

function heartbeat_views_views_query_alter(&$view, &$query) {

  // Add all necessairy fields when activity is loaded
  if ($view->base_table == 'heartbeat_activity') {
    foreach (_heartbeat_get_fields('heartbeat_activity') as $field => $alias) {
      $query
        ->add_field('heartbeat_activity', $field, $field);
    }

    // If relation is set with heartbeat_messages, add all fields for that table as well
    if (!empty($view->relationship['message_id'])) {
      foreach (_heartbeat_get_fields('heartbeat_messages') as $field => $alias) {
        $query
          ->add_field($view->relationship['message_id']->alias, $field, $alias);
      }
      $query
        ->add_field($view->relationship['message_id']->alias, 'variables', 'variables_orig');
      $query
        ->add_field($view->relationship['message_id']->alias, 'message', 'message_orig');
      $query
        ->add_field($view->relationship['message_id']->alias, 'message_concat', 'message_concat_orig');
    }
    else {
      drupal_set_message(t('Heartbeat views need to be joined over the heartbeat_messages table.'), 'error');
    }
  }
  $view->pager['_items_per_page'] = $view->pager['items_per_page'];
}