Displaying Reaction Points Total in Discussions Archive
Hallor,
Client wants to display points on the discussions archives page; I was just wondering if there was a relatively easy way to display the total quantity of points the article has accumulated across the comments on the discussions list. Halfway through writing this, I've finally realised that the $Discussion->Score is the total points on the start post of the discussion (Using only one test user was not making the test process easy!), so how challenging would it be to add ScoreTotal, which is updated on each reaction within the discussion? It doesn't sound too horrible challenging, but it is the end of the day and my brain is not at it's best, so I figured I'd ask the community! (And I apologise if this makes little sense/sounds like ramblings of nonsense)
Thanks in advance
Comments
Thanks for trying my addon!
You want the score of the discussion and any subsequent comments displayed somewhere?
Where?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Discussion Archive pages - so on the discussion list. The aim was to add it alongside the Views and Comments counts.
The SQL you are looking for would be something like this:
Ideally, you would hook into the discussion model and append this to your query before it is ran. I don't know how to subselect using the sql driver though.
Hopefully someone else can chime in as to how you could accomplish that.
Once you get the total score into the dataset, you can hook into your view and spit out the score like so:
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
If I remember it right, a subselect is not possible. But you can create a view with hard coded SQL and use that later on with the query builder
You could hook into the model after the retrieval, loop through the discussion objects, and perform the query on each one. Not very efficient, but it can be done:
Another option would be to add a denormalized field on the discussion table that is updated whenever one of it's children has a score change. This would definitely be more scalable and could be done by hooking into the reaction model after save reaction event.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Thank you so much for the help guys, I'll let you know how it goes when I get back onto this. (Sorry for the delayed response!)
I think the best option would certainly be the extra table route, we really don't want to have to load every discussion on page load just to count the votes. Sometime this week my boss should be making time for one of the back end dev's to give me a helping hand on this, so we'll probably look into implementing it then - I'll be sure to post up the code if anyone else is interested
I found a Vanilla subselect: https://github.com/vanilla/vanilla/blob/2.1/applications/vanilla/models/class.commentmodel.php#L143-155
Its magic is in those two lines:
I can actually just put the sub-select right into the join.
Great find, wish I could give you five insightfuls!
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
... but you didn't even gave me one
The catch is, that you cannot "just" join the select because it would be prefixed and so the prefix is set to "" when the join is made and afterwards it is restored to the old setting
Thanks to the input of @R_J, here is the plugin I came up with:
It should be perform better than the previous one.
I still don't think this is a very great idea since you are essentially assigning all the great commenters' content value to the initial discussion starter. That said, I hope you find it useful!
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
@hgtonight @R_J Thanks for all your help on this Saved me a whole lotta headaches and file trawling
And no, to be frank I don't think it's great either, but some clients don't give a flying fig what you have to say sigh
As far as I have understood it, it will display the sum of all comments in the discussions index.
I find that far more interesting that just the "worth" of the opening discussion. An interesting Discussion doesn't need to have any Comment worth reading at all and a worthless opening post could end up in a very good discussion. So taking a look at the sum of Discussion + Comments makes far more sense to me, than only showing one aspect of it.
That was the thinking behind it - the client's desire was to have separate votes to reactions (And then thanks separate to the both of them as well), which really is just over complicating it all. Reactions is one of the most advanced methods of judging the overall rating of something, thanks to the ability to apply different point values to different reactions etc. resulting in a much more organic representation of a discussion or questions worth.
If you are looking for great content, check out the best controller, which sorts all content based on score and date.
Don't listen to this cantankerous old fart. Do what you want!
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.