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.
Allow user to switch between discussions sorted by DateInserted and DateLastComment?
gharald
✭
Is there a way to create a navigational link that allows the user to toggle whether the discussion list is sorted by DateInserted and DateLastComment?
For example:
www.example.com/discussions/latest - displays discussions sorted by DateLastComment
www.example.com/discussions/newest - displays discussions sorted by DateInserted
Sorry if I am missing something obvious here - been poking around previous discussions of "sort by date last created" and didn't come up with anything.
Tagged:
0
Comments
There is no simple link for that. You have to create a plugin, but it should be fairly simply. If you like to, I could guide you.
Start with that one: http://vanillaforums.org/addon/howtovanillapage-plugin. Name it any other way and use it as a blueprint.
If you have it working, mimic the recent discussion page by copying the index() method of /applications/vanilla/controllers/class.discussionscontroller.php into the vanillaController_yourPluginName_create() function of the plugin.
Simply copying the contents will make your board crash, though. There some tweaks that you have to perform before the output will be like the recent discussions view. Start by replacing $this with $sender and report back the error messages if you get stuck.
If you manage to mimic the recent discussions view with your plugin, you must change this line https://github.com/vanilla/vanilla/blob/release/2.1/applications/vanilla/controllers/class.discussionscontroller.php#L136 in your copy.
But one step after the other...
I'll check it out! Thanks for the lead.
@R_J I edited howtovanillapage.php and changed all the instances of $this to $sender, but got:
PHP Fatal error: Call to a member function data() on a non-object in /home/brookmn4/public_html/plugins/HowToVanillaPage/views/howtovanillapage.php on line 2
Line 2 is this:
if ($sender->data('hasArguments')) {
The object $sender does not exist in that spot. See / check where it gets created
There was an error rendering this rich post.
http://stackoverflow.com/questions/3696874/what-is-the-meaning-of-this
http://www.php.net/manual/en/language.oop5.basic.php
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Okay, just to ensure that we start from the same spot, here is what I'm starting with:
You want to see a page that looks like the recent discussions page. So we have to create one. It is always a good start to look at plugins that did the same and that's why I adviced my HowTo plugin, but it will help, I guess, but it is not needed.
I created an empty directory, and copied the contents from the HowTo plugin in there. Then I searched for the index function of the discussions controller and copied it in the class of my plugin. I renamed it to vanillaController_latest_create($sender, $args).
Vanilla consists of a framework and applications that are build on top of that framework. Plugins extend the applications. Vanilla is really only an application and by calling my function the way I did, I told the framework that this function should be part of the Vanilla application ("vanillaController"). Additionally I gave it a name and those two informations are enough to tell the framework that this page should be accessible at yourforum.com/vanilla/latest
If you insert
echo 'HEUREKA!'; return;
right below thepublic function vanillaController_latest...
and call that page, you can ensure that at least that is working like you want it.From there on we will face several problems, but no severe ones, I suppose. But we will nevertheless have to track them. The error message you have posted should not show up. In my environment the first problem is
The "VanillaController" object does not have a "xgetCategoryIDs" method.
Oh wait, I've posted it and saw that you are using 2.1 - I'll have to do the same to be of any help. The code above is from 2.1 and that would look different
Sorry for the delay, but I'm involved in too many projects right now :-/
Pffff... what happens when you are not focused? You are talking rubbish. I was on a complete wrong track. It could be achieved way easier/much more elegant. I think I can finish it (although ugly and uncommented)
Here is a short plugin that does what you like: http://vanillaforums.org/addon/latest-plugin
Let me explain what I thought and what I did now. I thought I had to mimic the recent discussion page and only change the sort order. Then you would have to create a link for the new page and would be able to change between both pages. When looking at how you would be able to change the sort order, I found that all this could be done with a simple hook.
So I only created a function for that hook. Depending on the user "setting" the sort order is changed before discussions are shown. I added a link so that users can change this "setting" right above the discussion list.
Just try it, I guess it will be what you need.
@R_J thanks for doing this. I'll give it a whirl!