I'm trying to write a patch that defines a new sort criteria allows nodes to be listed based on the last time they were updated OR a comment was posted. This will support a "what's new" block that merges the two criteria. Attached is my initial patch that doesn't seem to work. My guess is that node_comment_statistics isn't being joined correctly but I haven't been able to decipher how to link it to the nodes via $query->add_table.

Comments

ChrisKennedy’s picture

StatusFileSize
new1.1 KB

Sorry, attaching the patch with -F^f included.

merlinofchaos’s picture

I think the problem was that it needs to be on the node_comment_statistics table in views_comment.inc not on node. THen you don't even have to ensure table.

Otherwise...it actually seemed to work ok for me without any changes.

I'm not committing this, though; it's incomplete. It needs fields and filters.

ChrisKennedy’s picture

Version: 4.7.x-1.x-dev » 6.x-2.x-dev
StatusFileSize
new3.18 KB

I took a stab and reimplementing it but wasn't able to get the basic field to work. Any advice would be much appreciated.

Here is the error I get when trying to view the last_changed field:

user warning: Unknown column 'node_comment_statistics.last_changed' in 'field list' query: SELECT node.nid, node.nid AS node_nid, node_comment_statistics.last_comment_timestamp AS node_comment_statistics_last_comment_timestamp, GREATEST(node.changed, node_comment_statistics.last_comment_timestamp) AS node_comment_statistics_last_changed, node_comment_statistics.last_changed AS node_comment_statistics_last_changed, node_comment_statistics.changed AS node_comment_statistics_changed FROM node node LEFT JOIN node_comment_statistics node_comment_statistics ON node.nid = node_comment_statistics.nid ORDER BY node_nid ASC, node_comment_statistics.last_comment_timestamp ASC LIMIT 0, 5 in /home/chrisken/public_html/test/includes/database.mysql.inc on line 167.

Even though I have set notafield to TRUE it's still showing up in the field list, and I can't get .changed from being listed either. Blegh.

merlinofchaos’s picture

+        'addlfields' => array('changed'),

That's where the .changed is coming from. You should not need any addlfields at all.

Your filter and sort handlers are going to totally fail. notafield only applies to fields (for sort and filter it automatically has that behavior) but youre using Views default handlers which assume regular fields.

Your other problem may be a cached query. Be sure to clear your cache and resave the view. (I have the patch basically working, and since this is so close I may finish it today).

ChrisKennedy’s picture

StatusFileSize
new3.82 KB

Yeah caching was messing me up. This version should work.

ChrisKennedy’s picture

Status: Needs work » Needs review
merlinofchaos’s picture

Status: Needs review » Fixed

Commited. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)