Filtering Categories from Best Of Page?

This discussion is related to the Yet Another Gamification Application addon.

Greetings,

First of all, excellent work with the application. YAGA was the main reason I was able to have the confidence to choose Vanilla as the platform of choice for our community. I've tried to do everything myself (and learned a lot about Vanilla/Smarty/CSS in the process, heh) but this time I'm stumped.

I have a question: is it possible to filter posts from specific categories out of the 'Best Recent Content' page? We have a private, invite-only category for users to post in. To clarify, if a user doesn't have the permission to view the category, they don't see it on the Best Recent Content page, which is fine, but I would like for users with the permission to see the category not to be able to see the posts appear in the Best Recent Content page. I've fiddled around with the code in '/applications/yaga/views/best/index.php', but I haven't been able to pinpoint how to extrapolate category IDs (in this case, the one I want to filter out is '16') from posts to get the post to not display.

Any pointers? For now, I've just disabled access to the Best Recent Content page, but I would like to re-enable it for my community in the future, as seeing the best-reacted content is a big part of the culture we've migrated from. Thanks so much for any help!

Comments

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    You spoke of "Best Recent Content" therefore I searched for that string, found that it is the translation of "Yaga.BestContent.Recent" which is used in class.bestcontroller.php:

      public function Index($Page = 0) {
        list($Offset, $Limit) = $this->_TranslatePage($Page);    
        $this->Title(T('Yaga.BestContent.Recent'));
        $this->_Content = $this->ActedModel->GetRecent($Limit, $Offset);
        $this->_BuildPager($Offset, $Limit, '/best/%1$s/');
        $this->SetData('ActiveFilter', 'Recent');
        $this->Render('index');
      }
    

    So you can see that the content displayed is fetched here: $this->_Content = $this->ActedModel->GetRecent($Limit, $Offset);

    There are several approaches now. The most Vanilla-like way would be to use an event that is fired in the code. If you follow the flow from controller to model to view, you will find that there is only one event fired: "GetCustomRecent". But that would only allow to add content, not to filter it in any way.

    Since there is no clean way to solve the problem, you would have to change some files, which you normally should avoid

    Change the controller

    After the content has been fetched from the model, do something to filter out that category. The problem is, that pagination will break: if you fetch 20 discussions and 19 are from a restricted category, only 1 discussion remains which would be plain wrong.

    Change the view

    Same problem like above

    Change the model

    Yes, what else. The preferred way would be to insert a "FireEvent" call to allow save interaction or, in this case maybe somewhat more elegant, make the required information available in the event.

    Search for

          $this->EventArguments['CustomSections'] = array();
          $this->FireEvent('GetCustomRecent');
    

    and add

          $this->EventArguments['Comments'] = &$Comments;
          $this->EventArguments['Discussions'] = &$Discussions;
    

    before those lines.

    That would allow you to write a plugin with a method

    public function bestController_getCustomRecent_handler($sender, $args) {
        // Loop through $args['Discussions'] and $args['Comments'] to filter out
        // all posts with the unwanted categories
    }
    


  • Thank you so much for the reply RJ! I very much appreciate it.

    I've been wracking over documentation (I'm still new at programming, php in particular) on trying to write the plugin. Specifically, I'm not sure how to tell the function not to grab the posts from the specific category ID based on the Discussions and Comments arguments. I understand if you'd rather not give me all the answers; you've already given me great information, I'll keep hammering at it. Thanks for all you do!

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    I've got only my mobile here, but if you show what you have got and where you get stuck, I try to support.

    If you are new to development, I would advice a step by step approach. First make as few changes /additions as needed : add the loop directly inside that YAGA model. If you get that running, create the plugin that does the changes. Just don't get lazy and do not finish that plugin! You will most probably forget we thy you have written those lines and you will have to work those changes on every update


Sign In or Register to comment.