HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

What controls My Discussions in v3.3?

jitrjitr New
edited March 2020 in Vanilla 3.x Help

Your help with an unexpected snag, please..

I was aiming to clone My Discussions (url: /discussions/mine) to let's say My Chats (url: /discussions/chat). Each to display discussions from a separate set of categories.

The problem is that no change to $wheres or anything else I tried in function mine in class.discussionscontroller had an effect on the list of discussions on the screen. Not even complete removal of the function.

There must be something else but where to look?

Thank you.

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    The problem is that no change to $wheres or anything else I tried in function mine in class.discussionscontroller had an effect on the list of discussions on the screen. Not even complete removal of the function.

    Please revert all that you did that way. You can achieve very heavy tweaking just by adding a plugin, never change existing files

    Create a plugin and add a method discussionsController_chat_create($sender, $args). Take over as much as possible from an existing view, e.g. from DiscussionsController->index()

    Replace the $this->render() with $sender->render('index', 'discussions', 'vanilla');

    You need to replace references to $this with references to $sender. Start with small parts - I would indeed advice to start with only the render call in that method and then add the rest step by step. The first calls to /discussions/chat will fail because some data must be passed to the view, but you will be able to figure that out, I guess. If not, just ask again!

  • R_JR_J Ex-Fanboy Munich Admin

    Just look what I have found! I really don't know why I have toyed around with it, but I threw together that sample at some day in the past. There is no real usecase for exactly that code, but it makes up a very good reference, I'd say!



       public function discussionsController_invited_create($sender, $Page = '0') {
           // return;
       // public function bookmarked($Page = '0') {
           $sender->permission('Garden.SignIn.Allow');
           Gdn_Theme::section('DiscussionList');
    
           // Figure out which discussions layout to choose (Defined on "Homepage" settings page).
           $Layout = c('Vanilla.Discussions.Layout');
           switch ($Layout) {
               case 'table':
                   if ($sender->SyndicationMethod == SYNDICATION_NONE) {
                       $sender->View = 'table';
                   }
                   break;
               default:
                   $sender->View = 'index';
                   break;
           }
    
           // Determine offset from $Page
           list($Page, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30));
           $sender->canonicalUrl(url(ConcatSep('/', 'discussions', 'invited', PageNumber($Page, $Limit, true, false)), true));
    
           // Validate $Page
           if (!is_numeric($Page) || $Page < 0) {
               $Page = 0;
           }
    
           $DiscussionModel = new DiscussionModel();
    
           $Wheres = array(
               'd.CategoryID' => '5'
           );
    
           saveToConfig('Garden.Permissions.Disabled.Category', true, array('Save' => false));
           $sender->DiscussionData = $DiscussionModel->get($Page, $Limit, $Wheres);
           saveToConfig('Garden.Permissions.Disabled.Category', false, array('Save' => false));
    
    /*
           $sender->DiscussionData = $DiscussionModel->getWhere($Wheres, $Page, $Limit);
           $sender->DiscussionData = $DiscussionModel->getin(
               array(7, 15, 20)
           );
    */
           $sender->setData('Discussions', $sender->DiscussionData);
           $CountDiscussions = $DiscussionModel->getCount($Wheres);
           $sender->setData('CountDiscussions', $CountDiscussions);
           $sender->Category = false;
    
           $sender->setJson('Loading', $Page.' to '.$Limit);
    
           // Build a pager
           $PagerFactory = new Gdn_PagerFactory();
           $sender->EventArguments['PagerType'] = 'Pager';
           $sender->fireEvent('BeforeBuildBookmarkedPager');
           $sender->Pager = $PagerFactory->GetPager($sender->EventArguments['PagerType'], $sender);
           $sender->Pager->ClientID = 'Pager';
           $sender->Pager->configure(
               $Page,
               $Limit,
               $CountDiscussions,
               'discussions/invited/%1$s'
           );
    
           if (!$sender->data('_PagerUrl')) {
               $sender->setData('_PagerUrl', 'discussions/invited/{Page}');
           }
           $sender->setData('_Page', $Page);
           $sender->setData('_Limit', $Limit);
           $sender->fireEvent('AfterBuildBookmarkedPager');
    
           // Deliver JSON data if necessary
           if ($sender->deliveryType() != DELIVERY_TYPE_ALL) {
               $sender->setJson('LessRow', $sender->Pager->toString('less'));
               $sender->setJson('MoreRow', $sender->Pager->toString('more'));
               $sender->View = 'discussions';
           }
    
           // Add modules
           $sender->addModule('DiscussionFilterModule');
           $sender->addModule('NewDiscussionModule');
           $sender->addModule('CategoriesModule');
    
           // Render default view (discussions/bookmarked.php)
           $sender->setData('Title', t('Invited'));
           $sender->setData('Breadcrumbs', array(array('Name' => t('Invited'), 'Url' => '/discussionsinvited')));
           $sender->render();
       }
    

    As you might see, the bookmarked() method has been my "inspiration"

  • R_JR_J Ex-Fanboy Munich Admin
  • R_JR_J Ex-Fanboy Munich Admin

    The plugin standards have changed, so you should also read the docs: https://docs.vanillaforums.com/developer/addons/addon-info/

  • jitrjitr New
    edited March 2020

    Thank you for this life saver, RJ.

    Yes, a plugin, based on on Resolved Discussions, is the plan.

    Tweak after not first!

  • @R_J Success. I applied your Bookmark model to My Discussions. Apart from one tweak it worked at once. 

    It took a while to find out what to tweak but Covid19 arrangements took up a huge amount of time last week.

    A very big thank you.

Sign In or Register to comment.