function heartbeat_block in Heartbeat 6.2
Same name and namespace in other branches
- 6.4 heartbeat.module \heartbeat_block()
- 6.3 heartbeat.module \heartbeat_block()
Implementation of hook_blocks()
File
- ./
heartbeat.module, line 277 - To fully understand this, you have to be familiar with the rules module. Lots of documentation can be found on http://drupal.org/node/298480 for an introduction and tutorial, but http://drupal.org/node/298486 is a lot of handy info for developers.
Code
function heartbeat_block($op = 'list', $delta = 0) {
if (user_access('heartbeat view messages')) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Personal heartbeat');
$blocks[0]['cache'] = BLOCK_NO_CACHE;
return $blocks;
case 'view':
if (variable_get('heartbeat_enabled', 1)) {
global $user, $language;
$max_gap = variable_get('user_activity_grouping_seconds', 3600);
$end_time = $_SERVER['REQUEST_TIME'] - (int) $max_gap;
// Retrieve the most receent heartbeat.
$messages = array();
// We really need every field
$sql = "SELECT * FROM {user_activity} WHERE \n\t (user_activity.uid = %d) AND (user_activity.language = '%s') AND timestamp > %d ORDER BY timestamp DESC";
$result = db_query($sql, $user->uid, $language->language, $end_time);
while ($heartbeat = db_fetch_object($result)) {
$messages[] = $heartbeat;
}
$block['subject'] = t('Recent heartbeat');
$messages = heartbeat_group_messages($messages);
$block['content'] = theme('heartbeat_block', $messages);
return $block;
}
default:
}
}
}