You are here

heartbeat_views.module in Heartbeat 6.3

Same filename and directory in other branches
  1. 6.4 views/heartbeat_views.module

File

views/heartbeat_views.module
View source
<?php

// $id: $

/**
 * Implementation of hook_views_api()
 *
 * This hook will tell views2 that user activity is available
 */
function heartbeat_views_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'heartbeat_views'),
  );
}

/**
 * Implementation of hook_views_pre_view()
 */
function heartbeat_views_views_pre_view(&$view, &$display_id = 0, &$args = null) {
  if ($view->tag == 'heartbeat' && !empty($view->result)) {
    _heartbeat_render_view($view);
    $view->rendered = TRUE;
  }
}

/**
 * Implementation of hook_views_pre_render()
 */
function heartbeat_views_views_pre_render(&$view) {
  if ($view->tag == 'heartbeat' && !empty($view->result) && !$view->rendered) {
    _heartbeat_render_view($view);
    $view->rendered = TRUE;
  }
}

/**
 * Helper function to (re-)render the messages
 * coming from views
 */
function _heartbeat_render_view(&$view) {
  $limit = $view->pager['items_per_page'];
  if ($limit <= 0) {
    $limit = variable_get('heartbeat_block_public_items_max', 25);
  }
  $access = $view->filter['access_type']->heartbeat_access;
  $heartbeat_relations = $view->filter['access_type']->heartbeat_relations;
  $view->result = _heartbeat_group_views_messages($view->result, $access, $heartbeat_relations, $limit);
}

/**
 * Helper function to group and merge message
 * built by the views module
 */
function _heartbeat_group_views_messages($messages, $access, $heartbeat_relations, $limit) {
  global $user, $language;
  $heartbeat = HeartbeatParser::instantiate('views_gen');
  $heartbeatInfo = new HeartbeatInfo();
  $heartbeatInfo->uid = $user->uid;
  $heartbeatInfo->access = $access;
  $heartbeatInfo->limit_view = $limit;
  $heartbeatInfo->user_relations = $heartbeat_relations;
  $heartbeatInfo->language = $language->language;
  $full_timespan = variable_get('heartbeat_activity_no_duplicate_seconds', 172800) - 1;
  $heartbeatInfo->time_span = date("G", $full_timespan) . ' hours';
  $user->heartbeat_relations = $heartbeatInfo->user_relations;
  $heartbeat
    ->set_info($heartbeatInfo);
  $heartbeat
    ->set_timespan_gap(variable_get('heartbeat_activity_grouping_seconds', 720));
  $heartbeat
    ->build_sets($messages);
  $heartbeat
    ->merge_sets();
  $messages = $heartbeat
    ->get_messages($limit);
  return $messages;
}

Functions

Namesort descending Description
heartbeat_views_views_api Implementation of hook_views_api()
heartbeat_views_views_pre_render Implementation of hook_views_pre_render()
heartbeat_views_views_pre_view Implementation of hook_views_pre_view()
_heartbeat_group_views_messages Helper function to group and merge message built by the views module
_heartbeat_render_view Helper function to (re-)render the messages coming from views