heartbeat_views.module in Heartbeat 6.3
File
views/heartbeat_views.module
View source
<?php
function heartbeat_views_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'heartbeat_views'),
);
}
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;
}
}
function heartbeat_views_views_pre_render(&$view) {
if ($view->tag == 'heartbeat' && !empty($view->result) && !$view->rendered) {
_heartbeat_render_view($view);
$view->rendered = TRUE;
}
}
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);
}
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;
}