There are lots of options in Views for displaying various fields of data. This is great, but it would be nice to have more 'Last Comment' options. Specifically, I'd like to display the Title of the most recent comment (or at the Body, anything I can get!).
Is there anything else I can do to achieve this view? Argument handling, perhaps?
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | views-last_comment.patch | 702 bytes | dawehner |
| #12 | views-last_comment.patch | 763 bytes | dawehner |
| #11 | views-last_comment.patch | 731 bytes | dawehner |
| #9 | views-last_comment.patch | 727 bytes | dawehner |
Comments
Comment #1
sunSupport for comments is very limited in Views 1.x. Consider upgrading to 6.x, please.
For 1.x, this feature request won't fix.
Comment #2
wuyang commentedbut it still less for "last comments"
Comment #3
Nick Brown commentedComment #4
Nick Brown commentedCan anyone provide suggestion on where in the code to begin looking as I'd like to have a go at implementing this, but I'm unfamiliar with drupals or views workings?
Comment #5
merlinofchaos commentedThe problem is that there isn't an easy field in the database to go looking up the last comment. You have to JOIN the comments table and figure out which the last comment is, which probably means a sub-select which means very poor performance. For that reason, Views is unlikely to contain this code.
To do this right means, I think, creating a second table to store this data, and the policy of the Views' module is to not create data like that. Instead, another module would need to store this data.
For those who want to work on this kind of functionality, you should start by looking through comment.views.inc which contains all of the views integration for comment module, and read through the handlers there. You will find that some of the queries are a little bit complicated.w
Comment #6
sunSee also #292984: Add cid to node_comment_statistics
Comment #7
Nick Brown commented#292984: Add cid to node_comment_statistics clearly suggest that getting this information should not be hard as node_comment_statistics now contains a link to the last comment, so should not mean poor performance, hopefully allowing inclusion in views.
Comment #8
dawehnerBut thats drupal core. Sure we could implement this feature in 7.x-3.x but it is just not possible on 6.x, because views doesn't rely on other modules / or would hack core.
You can write your own custom module, which changes the schema, and adds the field to the view.
Comment #9
dawehnerHere is a patch for this new feature. A easy development with a relationship
Comment #10
sunHeavily broken indentation. ;)
Powered by Dreditor.
Comment #11
dawehnerdamn :) Thx..
Comment #12
dawehnerI'm wondering whether it should be better placed under the comment group. Here is a patch for this.
Comment #13
sunTrailing white-space here.
Not sure, but is it usual to put cryptic internal keywords like "cid" into such titles?
Do we really need to specify both, identically?
Powered by Dreditor.
Comment #14
dawehnerI copied and past the code from this
The difference between label and title is, that title is show when adding new elements and label is shown in the overview.
Updated the patch : trailing white-space.
Comment #15
drippydrop commentedSTUPID QUESTION
******************
Is this patch specifically for Drupal 7?
******************
END STUPID QUESTION
Comment #16
dawehnerYes. Its not possible to use this patch on 6.x, because drupal core does not have this feature.
Comment #17
drippydrop commentedSadly that is a bummer... thanks for the quick reply and I look forward to be able to do something like this in version 7.
Comment #18
dawehnerI commited my last patch. If needed the text can be made better later.
Comment #20
donquixote commentedI understand there is a performance problem with this in D6.
However, not having this included in views will only make people roll their own hacks, with the same result and the same performance penalty - only with more work.
What about we provide the slow solution in D6 nevertheless, with a performance warning added? Probably in a lot of situations this will still be faster than a lot of other things that happen in the page request.
(otherwise, hoping for a D6 backport of #470258: Groupwise maximum ('representative') relationships)
Comment #21
donquixote commentedI would like to solve this with a separate custom/contrib module for D6, if there is no included solution in sight.
Unfortunately, I am still a bit lost with the views api.
I need to
- alter the schema for node_comment_statistics, add a cid column -> sounds doable.
- add a relation on node_comment_statistics pointing to the comment with the same cid. -> duh, lost.
So far I tried implementing a cheap workaround:
A relation that does match on last_comment_timestamp, instead of cid. This is horribly ugly, and will break whenever more than one comment has the same timestamp - which can happen if the comments are automatically created with some poorly done import script or whatever.
Nevertheless, the workaround is a useful experiment, and showed me where I hit the wall.
I was able to hack comment.views.inc, function comment_views_data(), to add the relationship to node_comment_statistics.
(on views 2.x for D6)
However, I did not manage to achieve this with a separate module.
What I would need is to alter the data definition for node_comment_statistics.
Is this possible?
-------
I reopen this as support request. It can be closed as a feature request, when it's finished.
Thanks!
Comment #22
dawehnerWrite a hook_views_api, see advanced help for more information.
Write a hook_views_data_alter(&$data) which does the same as the patch from above.
Just doing a c&p would be enough.
Change version to make it clear.
Comment #23
donquixote commentedThanks.
I did not see the hook_views_data_alter documented on
http://views.doc.logrus.com/group__views__hooks.html or
http://drupalcontrib.org/api/drupal/contributions--views--docs--docs.php...
Anyway, thanks, I will try.
Comment #24
dawehnerFeel free to create a patch and fix the docu :)
IN general it always helps to read the views implementation on the hooks in modules/modulename.views.inc
Comment #26
Dean Reilly commentedI don't know how far donquixote got with back-porting the patches but you can view my attempt here:
http://drupal.org/sandbox/DeanReilly/1587188
Comment #27
donquixote commentedOuch, did I overpromise last year? I absolutely don't remember.
I hope at least my explanations did help.