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
Comment #1
kalin9 commentedfyi, 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
Comment #2
chrism2671 commentedAny chance of getting this in alpha 9?
Comment #3
kalin9 commentedit looks like sort by views doesn't sort properly i just noticed. not sure if that's an issue with the patch or elsewhere
Comment #4
michelle@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
Comment #5
Max_Headroom commented@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.
Comment #6
Max_Headroom commentedre: #3
kalin9, Please can you give me more info on this? I can not reproduce this.
Comment #7
michelleOk, 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
Comment #8
kalin9 commentedthanks 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
Comment #9
michelle"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
Comment #10
kalin9 commentedgreat thank you Michelle
Comment #11
Mapi99 commentedWould 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
Comment #12
michelleHm... Yeah, I guess I didn't have any unviewed ones so I didn't notice what it did. Will look into it.
Thanks,
Michelle
Comment #13
michelleBit 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
Comment #14
amnion commentedI 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.
Comment #15
michelleChanging 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
Comment #16
Max_Headroom commentedHi 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.
Comment #17
michelleNo, 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
Comment #18
Max_Headroom commentedSuggestion: maybe put if exists(statistics) in. I did it like this:
In advanced_forum.module
and in advf-forum-topic-list.tpl.php
Comment #19
michelle@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
Comment #20
michelleThe original issue is long fixed. The issue of removing column when statistics isn't enabled is handled by a better patch.
Michelle
Comment #21
Kumar Pushyamitra commentedHi 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