Comment count issue in Views
fumbling - October 17, 2008 - 21:58
| Project: | Node comments |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
After switching from the core comment module to node comments, I was able to get everything working in terms of commenting. But I can no longer get a comment count field in the view I was using before. Is there something I need to do to my view (which is a list of nodes which have comments - powered by nodecomments - attached to them) to connect properly to some aspect of node comments so that I can resurface the comment count field in my view?

#1
I would also greatly appreciate this feature so I can give my users a list of Most-Commented-On Nodes and Least-Commented-On Nodes. Thank you for supporting Drupal 6!
#2
I'm looking for this functionality as well.
This has been marked as duplicate: http://drupal.org/node/331177
#3
I would like this feature too. In my case I want to show users a view that has nodes that are not commented on.
#4
Has anyone figured this out? I'm struggling to make two views:
All nodes which have 0 nodecomments
All nodes which have 0 nodereferrers (or all nodes which have 0 nodes nodereferencing them)
I would greatly appreciate knowing how to do this with views. For the 2nd one I tried doing nodereferrer by type argument (or by field), but there's no way to specify "has no values" - you can just specify a single node id or something..:/
-Bill
#5
i am willing to pay for this functionality. i dont know if it means a comment count filter in views, where i can say "show only nodes who have 0 nodecomments" - thats what im looking for and will pay maybe $50 for: so for all nodes on my site, i can have a view that lists every node that hasnt been commented on with a nodecomment. i think this works with regular comment module, so maybe someone could check that code out - i just dont know drupal development that well yet. thanks.
#6
You can get the functionality, if you copy the following lines from views module
modules/comment.views.inc:function comment_views_data()to nodecomment module'sviews/nodecomment.views.inc:comment_views_data()// ----------------------------------------------------------------------
// node_comment_statistics table
// define the group
$data['node_comment_statistics']['table']['group'] = t('Node');
// joins
$data['node_comment_statistics']['table']['join'] = array(
//...to the node table
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
// last_comment_timestamp
$data['node_comment_statistics']['last_comment_timestamp'] = array(
'title' => t('Last comment time'),
'help' => t('Date and time of when the last comment was posted.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// last_comment_name (author's name)
$data['node_comment_statistics']['last_comment_name'] = array(
'title' => t("Last comment author"),
'help' => t('The name of the author of the last posted comment.'),
'field' => array(
'handler' => 'views_handler_field_ncs_last_comment_name',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_ncs_last_comment_name',
),
);
// comment_count
$data['node_comment_statistics']['comment_count'] = array(
'title' => t('Comment count'),
'help' => t('The number of comments a node has.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'views_handler_argument',
),
);
// last_comment_timestamp
$data['node_comment_statistics']['last_updated'] = array(
'title' => t('Updated/commented date'),
'help' => t('The most recent of last comment posted or node updated time.'),
'field' => array(
'handler' => 'views_handler_field_ncs_last_updated',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_ncs_last_updated',
),
'filter' => array(
'handler' => 'views_handler_filter_ncs_last_updated',
),
);
and add the following handlers to
function nodecomment_views_handlers()// statistics'views_handler_field_ncs_last_comment_name' => array(
'parent' => 'views_handler_field',
),
'views_handler_sort_node_last_comment_name' => array(
'parent' => 'views_handler_sort',
),
'views_handler_field_ncs_last_updated' => array(
'parent' => 'views_handler_field_date',
),
'views_handler_sort_ncs_last_updated' => array(
'parent' => 'views_handler_sort_date',
),
'views_handler_filter_ncs_last_updated' => array(
'parent' => 'views_handler_filter_date',
),
then copy the files
views/modules/comment/views_handler*_ncs_*to nodecomment module's views subdirectory.I attach the result.
#7
I am at work right now, but I will try this out this evening. Could the maintainer of the nodecomments project please look at this and consider patching the main version (or updating it to a new release)?
#8
It works!
i extracted this zip file to my desktop, put my site in maintenance mode, deleted my site's old nodecomment folder, uploaded this nodecomment folder, ran update.php, and put my site back into live mode. now under Views2 filters there is an option for filtering by number of comments, and i confirmed that it works! I used "less than ____ # of comments" and put 1, so all with less than 1 nodecomment (0 nodecomments) Great!
Thank You!
-Bill
p.s. emailing you about payment
#9
Tested, and it's working fine.
#10
#11
i dont think this should be closed just yet. actually i don't know if this is a separate issue (if it is, please move it), but it is related to the functionality the patch in this issue provided.
background: i have node types with the following relationships..
A --> B --> C --> D (nodereferrer field relationships -->) (doesnt seem relevant at first glance)
D--> DD (nodecomment node)
so basically, there is a relationship using nodereferrer with great grandparent (A), grandparent (B), parent (C), and child (D). (doesnt seem relevant at first glance) then, the child can have nodecomment nodes (comments on type D).
i have a view which outputs a page display, and it has the following filters:
Node: Type = Term
Node: Published Yes
------> Node: Comment count > 0
Content: Facebook = 1
certain nodes (of type D) don't seem to be appearing in the view (i also tried Comment count >=1, effectively the same thing with no luck)
THESE NODES ALL SEEM TO BE NODES WHOSE PARENTS GRANDPARENTS OR GREAT GRANDPARENTS WERE CREATED A LONG TIME AGO
i dont know if that makes any sense based on the way the drupal database tables work or whether or not they get updated, but this is a serious issue in my opinion. i had to go into the database manually and do an edit:
i had to manually change the comment count from 0 to 1, on a node which indeed had a comment.
UPDATE `mydatabasename`.`node_comment_statistics` SET `comment_count` = '1' WHERE `node_comment_statistics`.`nid` =2273 LIMIT 1 ;
nid is a node of type D which did have a nodecomment. for some reason the statistic wasn't being updated, so it may not be directly a problem with views. i have no idea. for now i am forced to update certain nodes that are added to the database, yet any with a totally new family structure A->B->C->D + nodecomment DD, work fine.
thanks, and if anyone would like me to clarify anything from this post please ask.
-b
#12
can you please provide this as a patch? As the new maintainer it would be much easier for me to review.
see http://drupal.org/patch/create
#13
the problem is i don't actually know how to fix the module. i was hoping someone else could come up with a patch, because it seems like with further testing the node comment statistics comment count is just generally not updating (seemingly at random, it's set to 0 instead of 1 even though a nodecomment is made). i have to go into the node comment statistics table and browse, sort by nid descending to get the most recent nodes, check and see if nodes with comments have a "0" when they should have a "1" and change to a 1 (or higher number if there is more than one comment per node).
#14
i have created a patch that i think addresses the issue. here's what i found:
the node_comment_statistics table was only getting updated for comments made on published parent nodes. what was happening in my case was that if a node was created but remained unpublished (moderated, for example) and was nodecommented on before it was approved/published, the node_statistics table was not being updated (comment count still remained at 0). then, when the original parent node was approved/published, and the nodecomment was approved/published, the count still remained at 0. i dont see why we can't just remove the constraint that the original parent node have to be published (n.status = 1 is not necessary... we have other means to deal with published status that this module shouldnt be handling - is there ever a case where you would not want to record that a comment was made (or a number of comments) just because the parent node is unpublished? i cant think of a case).
so, i removed "AND n.status=%d ... , 1" from one line
and removed "AND n.status = 1" from another line
it now seems to work fine for my situation, i tested by adding a parent node (unpublished/moderated status), commenting with a nodecomment twice and watching the count increment to 1 and then 2, then deleting both comments one at a time and watching the count go from 2 back to 1 and then 0, and then i added another nodecomment to bring it back up to 1. seems fine, and makes views integration nodecomment count work without having to manually update the table whenever someone comments on their own unpublished node.
thanks!
- $count = db_result(db_query('SELECT COUNT(*) FROM {node_comments} nc INNER JOIN {node} n ON n.nid = nc.nid WHERE nc.nid = %d AND n.status = %d', $nid, 1));
+ $count = db_result(db_query('SELECT COUNT(*) FROM {node_comments} nc INNER JOIN {node} n ON n.nid = nc.nid WHERE nc.nid = %d, $nid));
- $last_reply = db_fetch_object(db_query_range('SELECT nc.cid, nc.name, n.created, n.changed, n.uid FROM {node} n LEFT JOIN {node_comments} nc on n.nid = nc.cid WHERE nc.nid = %d AND n.status = 1 ORDER BY cid DESC', $nid, 1, 0, 1));
+ $last_reply = db_fetch_object(db_query_range('SELECT nc.cid, nc.name, n.created, n.changed, n.uid FROM {node} n LEFT JOIN {node_comments} nc on n.nid = nc.cid WHERE nc.nid = %d ORDER BY cid DESC', $nid, 1, 0, 1));
#15
p.s. this looks like, in my opinion, it should also be applied to the 2.x dev
#16
subscribe
#17
I would appreciate this feature too... subscribing
#18
Hey, you're missing a single quote after %d on the first query in your patch.
#19