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.
Statistics based on Likes
tristan_v
New
Hi, is it possible to generate a list of all discussions/comments by Likes, from the dashboard maybe? To see what users are Liking, etc.
Tagged:
0
Comments
Sure! Here is a start. After enabling the plugin with the great name "I Like Statistics", you'll be able to see a small and really ugly table if you go to yourforum.com/plugin/ilikestatistics
If you look at the code you'll find out that you do not need much to get this started. It will take some more effort if you want to make look it more nice, but it wouldn't be too hard either. Just give me a signal that you are willing to work on it by yourself and I'd be happy to guide you.
Yes, thats exactly what I'm needing, thank you! Is there a way to incorporate that table into the dashboard, instead of a separate page?
Yes, of course. But it will be a little more complex.
Create a subfolder in the new plugins folder called
views
and a file calledilikestatistics.php
. There you should place that<table>...</table>
markup.In your plugin, where that markup has been, insert the following line:
$sender->render($this->getView('ilikestatistics.php'));
. This line will load the views that you have created in step 1 and instead of simply writing out that code to the browser, it embeds it in Vanilla. Try it now before you proceed! (You should better take a look at what is happening after each step. In case of something not working, you would be able to tell in which step something has gone wrong)You see that "something"" is there, which can be identified as being part of the dashboard and part of the table, but it is not very satisfying. One step after the other. Where is the sidepanel? We have given no information so it is not rendered, so let's do it! Put that line right above the $sender->render...
$sender->addSideMenu('plugin/ilikestatistics');
. It tells the side menu which menu entry should be highlighted. Go and try...Cruel joke - we do not see a menu entry! But at least the menu is there. To insert a menu entry, we have to insert more than a one liner. It will be three:
Throughout the sourcecode of Vanilla there are function calls like
fireEvent('getAppSettingsMenuItems')
and some variables are passed in as arguments. When the program comes to such a fireEvent call, all plugins that handle such an event have the possibility to insert code or change the passed variables, etc. When the SettingsMenu is build, we have the possibility to add an item. And that's what we did here. We told Vanilla to add a link to the section Dashboard, make its text "I Like Statistics", gave the link to our page and finally decided that only users with the 'ILikeStatistics.View' permission should be able to see it (admins always have all permissions anyway). If you try it now, you'll see the link in the dashboard sections which makes you page easily accessible right now. Fine, but the data seems to be missing.Are you a programmer? Ever heard of variable scope? We've stuffed the top ten discussions in our $topTen variable. But when our view is rendered by that other function, the $topTen variable will be unknown. So we have to pass the data over. There is a handy function available. If you add
$sender->setData('TopTen', $topTen);
before the $sender->render... line, you make the content of that variable available for the coming controller actions. But the variable $topTen is still not accessible in the view and that's why we have to change something there, too. In the view you have to access the data by replacing$topTen
with$this->data('TopTen')
.That worked like a charm! Thank you very much. Also helped me learn a bit more about how the whole process works.