Statistics module must be enabled and Count content views must be enabled in admin/logs/settings
In d6_compat.inc (I know you said not here, but this is just to show)
Find:

// Create the tablesorting header.
  $ts = tablesort_init($forum_topic_list_header);
  $header = '';
  foreach ($forum_topic_list_header as $cell) {
    $cell = tablesort_header($cell, $forum_topic_list_header, $ts);
    $header .= _theme_table_cell($cell, TRUE);
}

Replace all with:


  $advanced_forum_topic_list_header = array(
    array('data' => ' ', 'field' => NULL),
    array('data' => t('Topic'), 'field' => 'n.title'),
    array('data' => t('Replies'), 'field' => 'l.comment_count'),
    array('data' =>t('Views'), 'field' =>'l.topic_views'),
    array('data' => t('Created'), 'field' => 'n.created'),
    array('data' => t('Last reply'), 'field' => 'l.last_comment_timestamp'),
  );
  // Create the tablesorting header.
  $ts = tablesort_init($advanced_forum_topic_list_header);
  $header = '';
  foreach ($advanced_forum_topic_list_header as $cell) {
    $cell = tablesort_header($cell, $advanced_forum_topic_list_header, $ts);
    $header .= _theme_table_cell($cell, TRUE);
  }

in advanced_forum module, add this function:

/**
 * Retrieves a forum's "views count".
 *
 * @param $nid
 *   node ID
 *
 * @return
 *   - totalcount: count of the total number of times that node has been viewed.
 */
 function views_count_get($nid) {

  if ($nid > 0) {
    $views_count = db_result(db_query('SELECT totalcount FROM {node_counter} WHERE nid = %d', $nid));
  }

  return $views_count;
}

In advf-forum-topic-list.tpl.php find:

<td class="created"><?php print $topic->created; ?>

Before add:

<td class="views"><?php print  views_count_get($topic->nid);?> </td>

In advanced_forum.css, at the end, add:

/*****************************
forum.css overrides
******************************/
#forum td.created, #forum td.posts, #forum td.topics, #forum td.last-reply, #forum td.replies, #forum td.pager, #forum td.views {
  white-space: nowrap;
}
#forum td.posts, #forum td.topics, #forum td.replies, #forum td.pager, #forum td.views {
  text-align: center;
}

Comments

kalin9’s picture

fyi, i did the above against alpha8, tested in ie6, ie7, ff 2.x, opera, ff3.x beta in multiple resolutions it's working fine for me and is quite nice to have i might add.

thanks for posting this

chrism2671’s picture

Any chance of getting this in alpha 9?

kalin9’s picture

it looks like sort by views doesn't sort properly i just noticed. not sure if that's an issue with the patch or elsewhere

michelle’s picture

@chrism2671 - I hope so. This one is a priority for me, but I had someone willing to pay me to bump up a couple other features so I need to get those done, first. :)

Michelle

Max_Headroom’s picture

@kalin9
I'm out of office this week and will look over the weekend at the sort by views problem.

@Michelle
Willing to pay me to bump this? :) (Joke)
What can I do to help? Can you give me some pointers with what to do with the code in D6_compat? I also need to put in checks that statistics module is enable.

Max_Headroom’s picture

re: #3
kalin9, Please can you give me more info on this? I can not reproduce this.

michelle’s picture

Status: Needs review » Fixed

Ok, added to the commit queue. Sorting by the views column will not be possible without redoing vast amounts of core and causing a performance hit.

Michelle

kalin9’s picture

thanks for checking zandroc

basically I just click on the views column to sort, and so that it requests the forum with ?sort=asc&order=Views

but the displayed posts are not sorted by views. Looking at the list I can't figure out how they're sorted, it doesn't seem to be by any criteria that I can discern.

I'm doing this on a forum that has at least one sticky, and enough topics for there to be multiple pages. I have many different view counts on the posts, some as low as 5 some up to 700 or 800 and in between. There appears to be no rhyme or reason to the sort by view.

Per Michelle's comment though it sounds like perhaps he knows what's going on, and it's a job to remedy. Perhaps it'd be best to make the views column not clickable to avoid frustrating users.

thanks

michelle’s picture

"Perhaps it'd be best to make the views column not clickable to avoid frustrating users."

It isn't. It's not possible to make it sortable without replicating vast quantities of core to redo the query that the tablesort is based on. So I just made it not clickable. My version of this was comitted yesterday, btw. Got my comitting issues solved.

Michelle

kalin9’s picture

great thank you Michelle

Mapi99’s picture

Would it not be better to have 0 as default under the views instead of an empty column?
Perhaps you could look into this Michelle,

- Mapi

michelle’s picture

Status: Fixed » Active

Hm... Yeah, I guess I didn't have any unviewed ones so I didn't notice what it did. Will look into it.

Thanks,

Michelle

michelle’s picture

Status: Active » Fixed

Bit of a weird edge case since the only way I could get an unviewed topic was to delete the views in the db but, anyway, I initialized the variable to 0 so it shows 0, now, if it's unviewed.

Michelle

amnion’s picture

Version: 5.x-1.0-alpha7 » 5.x-1.0-alpha8

I added all this and double checked that the code was right. My forums now have the views column, but the "created" info just shifted left into the views column, the "last reply" info shifted into the created column, and the final column is empty. Can't figure out which part could be the problem.

michelle’s picture

Version: 5.x-1.0-alpha8 » 5.x-1.x-dev
Status: Fixed » Active

Changing the version since this isn't in alpha 8.

I've only tested this on my dev site, so it's possible there's something that didn't get into the tarball. Re-opening this until I get a chance to give the dev a good testing.

Michelle

Max_Headroom’s picture

Status: Active » Needs review

Hi Michelle

I see you've fixed this in the new dev.

Also, I would suggest that you put statistics in the dependencies list of the .info file so that the statistics module gets enabled.

michelle’s picture

Status: Needs review » Fixed

No, I don't want to make statistics a requirement because it is only needed for this one thing and someone may choose to go without it if they don't want the overhead.

This is working fine in my testing other than the showing 0 instead of blank issue, which I just fixed, so marking this fixed again.

Michelle

Max_Headroom’s picture

Status: Fixed » Needs review

Suggestion: maybe put if exists(statistics) in. I did it like this:
In advanced_forum.module

global $forum_topic_list_header;
	$forum_topic_list_header = array();
	if (module_exists(statistics)){
		$forum_topic_list_header = array(
		array('data' => '&nbsp;', 'field' => NULL),
		array('data' => t('Topic'), 'field' => 'n.title'),
		array('data' => t('Replies'), 'field' => 'l.comment_count'),
		array('data' => t('Views'), 'field' => NULL),
		array('data' => t('Created'), 'field' => 'n.created'),
		array('data' => t('Last reply'), 'field' => 'l.last_comment_timestamp'),
		);
	}else{
		$forum_topic_list_header = array(
		array('data' => '&nbsp;', 'field' => NULL),
		array('data' => t('Topic'), 'field' => 'n.title'),
		array('data' => t('Replies'), 'field' => 'l.comment_count'),
		//array('data' => t('Views'), 'field' => NULL),
		array('data' => t('Created'), 'field' => 'n.created'),
		array('data' => t('Last reply'), 'field' => 'l.last_comment_timestamp'),
		);
	}

and in advf-forum-topic-list.tpl.php

<?php if (module_exists(statistics)){ ?>
      <td class="views"><?php print $topic->views;?> </td>
      <?php } ?>
michelle’s picture

@Zandroc - Good suggestion but I'm going to hold off on this a bit. This whole section of code will be moving, soon, and I'll do it then.

Michelle

michelle’s picture

Status: Needs review » Closed (fixed)

The original issue is long fixed. The issue of removing column when statistics isn't enabled is handled by a better patch.

Michelle

Kumar Pushyamitra’s picture

Hi Kalin,

$advanced_forum_topic_list_header = array(
array('data' => ' ', 'field' => NULL),
array('data' => t('Topic'), 'field' => 'n.title'),
array('data' => t('Replies'), 'field' => 'l.comment_count'),
array('data' =>t('Views'), 'field' =>'l.topic_views'),
array('data' => t('Created'), 'field' => 'n.created'),
array('data' => t('Last reply'), 'field' => 'l.last_comment_timestamp'),
);
In this Views field name is l.topic_views but this column is not available in node_comment_statistics
in place of this you need to use
$advanced_forum_topic_list_header = array(
array('data' => ' ', 'field' => NULL),
array('data' => t('Topic'), 'field' => 'n.title'),
array('data' => t('Replies'), 'field' => 'l.comment_count'),
array('data' =>t('Views'), 'field' =>'nc.totalcount'),
array('data' => t('Created'), 'field' => 'n.created'),
array('data' => t('Last reply'), 'field' => 'l.last_comment_timestamp'),
);

totalcount column is from node_counter
and change the query of line number 582 in forum.module
$sql = db_rewrite_sql("SELECT n.nid, r.tid, n.title, n.type, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments, f.tid AS forum_tid FROM {node_comment_statistics} l INNER JOIN {node} n ON n.nid = l.nid INNER JOIN {users} cu ON l.last_comment_uid = cu.uid INNER JOIN {term_node} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {forum} f ON n.vid = f.vid WHERE n.status = 1 AND r.tid = %d");
to
$sql = db_rewrite_sql("SELECT n.nid, r.tid, n.title, n.type, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments, f.tid AS forum_tid ,nc.totalcount FROM {node_comment_statistics} l INNER JOIN {node} n ON n.nid = l.nid INNER JOIN {users} cu ON l.last_comment_uid = cu.uid INNER JOIN {term_node} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {node_counter } nc ON n.nid = nc.nid WHERE n.status = 1 AND r.tid = %d");

hope this will help you