Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Looking for a simple way to fetch a discussion
I'm setting up vanilla for a small forum, and things are going well but there is one thing missing: I'd like to show the most recent discussion from a specific forum as a newspost on the frontpage of the site,
My problem is that I can't seem to find an easy-to-use API to fetch discussions/comments. I've been through the Discussioncontroller, but that code doesn't seem very re-usable, and the json-api app is kinda daunting since I've never used json before.
What would be the easiest way to do this in?
My problem is that I can't seem to find an easy-to-use API to fetch discussions/comments. I've been through the Discussioncontroller, but that code doesn't seem very re-usable, and the json-api app is kinda daunting since I've never used json before.
What would be the easiest way to do this in?
Tagged:
1
Comments
SELECT *, `GDN_Discussion`.`DiscussionID` AS ID FROM `GDN_Discussion` ORDER BY `GDN_Discussion`.`DateUpdated` DESC LIMIT 0, 1;
to retreive a last updated discussion and selecting:
SELECT * FROM `GDN_Comment` WHERE `GDN_Comment`.`DiscussionID` = ID ORDER BY `GDN_Comment`.`DateInserted` ASC;
to retreive comments for the discussion, where ID is DiscussionID returned in the first select.
Also, you might want to use some kind of a database abstraction layer behind your SQL command to protect yourself against injection. If you're using any kind of CMS, you should use its built in methods for accessing the database.
On a side not, I've now gotten progress with simply copying the discussionscontroller+views and making a "blogcontroller", but it's all very hackish and unmaintainable, I need a better solution..
I'd wish there was someone who could explain exactly where and how the discussioncontroller does its queries, so I could reuse them for a CustomPages page and still be able to get all the userinfo (avatars etc.) and formatting.
I'm very thankful for the help so far, though
You need the last discussion updated, so you use DateUpdated DESC.
Then you need all comments for the discussion from the first to last inserted, so DateInserted ASC. But if you want to have last on top, then you use DESC.
@chi1 I see.
Good luck with that. Would be nice to have a blog possibility. Anyway, it might be better to write Blog as new Garden Application, though I don't understand the architecture of Vanilla yet.
Vanilla Forums COO [GitHub, Twitter, About.me]
If you're using a plugin to implement these changes, you can create a method on DiscussionModel using our event framework, like this:
public DiscussionModel_GetOrdered_Create($Sender) { // Code here }
As for what the code in there should kinda look like... check out applications/vanilla/models/class.discussionmodel.php for inspiration
Vanilla Forums COO [GitHub, Twitter, About.me]
I'll be sure to post it when I'm fully done.
It's very rough, but I figured it might be useful to someone.