How do i load / call a stream? In the api i see hook_heartbeat_stream_load but that function should be used to modify a stream once it's loaded.

I looked trough the block code in heartbeat.module but couldn't really find how or where you call a stream.

Comments

Stalski’s picture

Status: Active » Fixed

If you follow the menu paths , E.g. in pages.inc or you follow the block view code, you'll find your way.
I will be something like:

  // Get the active stream.
  $heartbeatStream = heartbeat_stream($stream_name, $page);
  // maybe change some properties, view mode, whatever.
  if (!$heartbeatStream) {
  	drupal_access_denied();
  	return;
  }
  else {

    // When view a streams specific for a user (E.g. stream blocks on profile page),
    // alter the viewed person.
    if (!$page && is_numeric($account) && $account > 0 && variable_get('heartbeat_show_user_profile_messages_' . $stream_name, 0)) {
      $heartbeatStream->setViewed(user_load($account));
    }
    // For blocks calling this page in general.
    elseif (isset($_GET['uid']) && is_numeric($_GET['uid']) && $_GET['uid'] > 0) {
      $heartbeatStream->setViewed(user_load($_GET['uid']));
    }

    // If OG related messages are excluded.
    if (!empty($heartbeatStream->config->settings['exclude_og'])) {
      $heartbeatStream->excludeOg(TRUE);
    }

    // Build the stream output.
    heartbeat_stream_build($heartbeatStream);

    $build = heartbeat_stream_view($heartbeatStream, $view_mode);
Michsk’s picture

I'm stuck at:

function user_heartbeat_content_render($subtype, $conf, $args, $context) {
	$block = new stdClass();
	$viewing = user_load(arg(1));
	
  // Get the active stream.
	$stream_name = 'useractivity';

	if ($heartbeatStream = heartbeat_stream($stream_name, FALSE, $viewing)) {
		
		heartbeat_stream_build($heartbeatStream);
		$build = heartbeat_stream_view($heartbeatStream);
		$block->content = array();
		$block->content['#theme'] = 'heartbeat_list';
		$block->content['#stream'] = $heartbeatStream;
		$block->content['#content'] = $build;		
	}
	else {

		$block->content = t('Niks te melden');
	}

	return $block;
}

All it returns is 'No activity yet.' tough the user has got activity.

I also don't get what heartbeat_stream_build() does, i got it from the examples you showed (block and page).

I'm trying to show the stream in ctools custom content.

Michsk’s picture

Is it possible to display a heartbeat stream, without having a page and block for it? I want to display it in a content type so i can use it in panels.

Michsk’s picture

Got it working with:

function user_heartbeat_content_render($subtype, $conf, $args, $context) {
	$block = new stdClass();
	$viewing = user_load(arg(1));
	
  // Get the active stream.
	$stream_name = 'useractivity';
	
	$heartbeatStream = heartbeat_stream($stream_name, 1);

	if ($heartbeatStream) {
		
		$heartbeatStream->setViewed($viewing);
		heartbeat_stream_build($heartbeatStream);
		
		$build = heartbeat_stream_view($heartbeatStream, 'default');

		$block->content = array();
		$block->content['#theme'] = 'heartbeat_list';
		$block->content['#stream'] = $heartbeatStream;
		$block->content['#content'] = $build;		
	}
	else {

		$block->content = t('Nog geen activiteiten');
	}

	return $block;
}

Only question left is how is this going to be displayed? Since i don't see a option for pager, and amount of results?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.