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.

Dev Question: FIltering all discussion queries by selected categories

I'm just wondering the best way to go about this.

I have a forum with some metadata against each category. That metadata will determine which categories a user can see at any time. I would like to limit the discussions a user can see to just the discussions that match the relevant metadata.

I have looked at add-ons such as hidecategories that visually hide posts in specified categories using just CSS. I would like to filter these discussions at the query level - so when a discussion query is performed, or when a search is done, only a sub-set of categories is included in the results.

Now in WordPress there is a central core query object that performs all the queries, and you can hook into that to modify how it filters results. That same query object is used in all instances - searching, index pages, displaying posts etc. Is there something similar in Vanilla that can be hooked into, or are the queries distributed all over the place?

Now, this is not a permissions-based thing. I do not want to use roles to prevent a user from ever seeing a category. I just want to effectively layer a category-based filter over the top of all discussion queries. Is there is an add-on that does something like this, that may give me some pointers?

-- Jason


  • edited December 2012

    A quick glance through the code gives me a trigger in ConversationModel->Get() where I can put in additional conditions. A trigger would probably be useful a level up from this, in ConversationModel->ConversationQuery() I'll investigate these to see if it fits my needs.

  • peregrineperegrine MVP
    edited December 2012

    look at vanilla/views/categories/discussions.php

    and everything related to categories and CategoryModel

    conversations refer to inbox messages - you are barking up the wrong tree so to speak.

    you could do several things - for the page to work correctly - you probably need to filter in the core at line 105 with a join to your meta.


    $this->DiscussionData = $DiscussionModel->Get($Page, $Limit);

    these are just possible hints - I'm not writing it for you, unless of course you want to make me an offer.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Ah, of course - the distinction between conversations and discussions; same thing in the real world, but very different in Vanilla.

    I don't think I need to touch the controller at all. This is filtering that I need, so can apply to the module only. It looks like the DiscussionModel has a BeforeGet trigger where I can inject a join to the categories, or a condition of some sort. The data that will feed into the condition comes from the session or user profile, so there is nothing for the controller to pass in.


    -- Jason

  • peregrineperegrine MVP
    edited December 2012

    You're right. I never noticed the BeforeGet event before :). Much simpler as you say. Used in several plugins. You learn something new everyday, sometimes.

    You joined vanilla forums a day before me. - that could be it.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • edited December 2012

    I actually joined many years ago, but have lost my login several times and have no idea how to merge accounts together as one. Kind of rusty though, but catching up as I'm remembering where to look :-)

    It's much the same as I remember it - too much in the controllers (a log of which should probably be in the models), too many duplicated queries across the site IMO, too many assumptions on which directions forums will scale (based on which data is serialized before being stored, making it impossible to query if it grows too large) in the real world, but otherwise a hundred times better than any other forum for customising once you know where the limits are.

    Looking forward to a bit of locale/language-based development for a client, with hopefully some generic plugins that can be released on the back of it.

Sign In or Register to comment.