Exisiting Blocks or similar things only show active topics, or recent posts. Nothing useful for a forum.

I build something to show me a list of topics, where new comments are included, with a link to jump directly there (to be precise, it's the last page)

1. The view (can be imported on the views section)

$view = new stdClass();
  $view->name = 'forumTracker';
  $view->description = 'Shows all new Forumposts';
  $view->access = array (
  0 => '2',
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'Forum - New Posts';
  $view->page_header = 'To mark everything as read, use the "mark as read"-link on <a href="forum">Forums</a>!';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'table';
  $view->url = 'forum/forumTracker';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '25';
  $view->menu = TRUE;
  $view->menu_title = 'New Posts';
  $view->menu_tab = FALSE;
  $view->menu_tab_weight = '0';
  $view->menu_tab_default = FALSE;
  $view->menu_tab_default_parent = NULL;
  $view->menu_tab_default_parent_type = 'tab';
  $view->menu_parent_tab_weight = '0';
  $view->menu_parent_title = '';
  $view->sort = array (
    array (
      'tablename' => 'node_comment_statistics',
      'field' => 'last_comment_timestamp',
      'sortorder' => 'DESC',
      'options' => 'normal',
    ),
  );
  $view->argument = array (
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => 'Title',
      'handler' => 'views_handler_field_nodelink_with_mark',
      'sortable' => '1',
      'options' => 'link',
    ),
    array (
      'tablename' => 'users',
      'field' => 'name',
      'label' => 'Author',
      'sortable' => '1',
    ),
    array (
      'tablename' => 'node_comment_statistics',
      'field' => 'comment_count',
      'label' => 'Answers',
      'handler' => 'views_handler_comments_with_new',
    ),
    array (
      'tablename' => 'node_comment_statistics',
      'field' => 'last_comment_timestamp',
      'label' => 'Last Post',
      'handler' => 'views_handler_field_since',
      'sortable' => '1',
      'defaultsort' => 'ASC',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'forum',
),
    ),
    array (
      'tablename' => 'history',
      'field' => 'timestamp',
      'operator' => '0',
      'options' => '',
      'value' => array (
  0 => '0',
),
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node_comment_statistics, node, users, history);
  $views[$view->name] = $view;

2. Modify the template.php from your theme to get the "new"-Link jumping to the last page instead of the first one:
(from http://drupal.org/node/154084 )
therefore we modify the link to fit our needs.

function phptemplate_views_view_table_forumTracker($view, $nodes, $type) {
  $fields = _views_get_fields();
  $comments_per_page = _comment_get_display_setting('comments_per_page');

  foreach ($nodes as $node) {
    $row = array();
    foreach ($view->field as $field) {
      if ($fields[$field['id']]['visible'] !== FALSE) {
		if($field['field'] == 'comment_count')
		{
  		    $count = db_result(db_query('SELECT COUNT(c.cid) FROM {comments} c WHERE c.nid=%d', $node->nid));
		    // Find the ending point. The pager URL is always 1 less than
		    // the number being displayed because the first page is 0.
	            $last_display_page = ceil($count / $comments_per_page);
	            $last_pager_page = $last_display_page - 1;

		    $cell['data'] = $node->node_comment_statistics_comment_count.'<br>'.l('new', 'node/'.$node->nid, array(), 'page='.$last_pager_page.'#new');
        	    $cell['class'] = "view-field ". views_css_safe('view-field-'. $field['queryname']);
        	    $row[] = $cell;
		}
		else
		{
			$cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
    	                $cell['class'] = "view-field ". views_css_safe('view-field-'. $field['queryname']);
        	        $row[] = $cell;
		}
      }
    }
    $rows[] = $row;
  }
  return theme('table', $view->table_header, $rows, array('cellspacing'=>'40', 'border'=>'1'));
}

That's it.
Any improvements or hints are welcome! :)

Comments

michelle’s picture

Could you create a handbook page for this? Since the module isn't dependent on views, I'm not sure I want to include views with it... I might, at some point, especially when we get to the panels integration, but that's a ways off. In the mean time, it would be great in the handbook. I'd rather not leave it as an active issue because then I'll keep forgetting what it is and opening it over and over. :)

Michelle

maulwuff’s picture

Status: Active » Closed (fixed)

Ok, to save you some time ;)
It is located here:
http://drupal.org/node/234200

michelle’s picture

Status: Closed (fixed) » Fixed

Thanks!

Setting this fixed. It will close automatically in 2 weeks and that gives people time to see it.

Michelle

maulwuff’s picture

leave out ", array('cellspacing'=>'40', 'border'=>'1')" on the last line for a clean table. FF did not show it, but IE6 and 7 did. Sorry.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

scedwar’s picture

Status: Fixed » Active

Apologies if I'm out of order reopening this, but I was wondering whether anyone had considered a solution to the views/comments problem with this module: http://drupal.org/project/comment_page or this module http://drupal.org/project/comments_page and whether they would break adv_forum? It seems to take a different approach to trying to actually changing comments into nodes (which would obviously cause a lot of problems).

I'm looking to integrate my forums into the main drupal system and would like to be able to produce pages of "all recent posts/comments" - essentially a news feed of everything on the site (with optional filters).

Any thoughts?

michelle’s picture

Status: Closed (fixed) » Fixed

Comment page works fine with advforum, though there was a typo that kept the link from showing which I hadn't noticed, thanks. Just fixed it. Your second link doesn't go anywhere so I don't know what it is. Changing comments to nodes breaks forum which would make advforum not work.

Michelle

scedwar’s picture

Status: Active » Fixed

Sorry, the link should have been http://drupal.org/project/comments_page (confusingly similar).

michelle’s picture

Ah, that one. Yeah, that should work just fine with advforum.

Michelle

Anonymous’s picture

Status: Fixed » Closed (fixed)

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