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.

Can I keep private categories discussion tags from showing up in Popular Tags?

I have a moderator's area, and I'd like them to be able to tag their discussions without those tags showing up for every user.

Best Answer

  • hgtonighthgtonight MVP
    Answer ✓

    Yes. It is possible, but might get a little messy. You would have to validate permissions to view each discussion that has a tag and filter the results in the module.

    Something like this will get you started:

      // Loop through the IDs in the tagging 
      $DiscussionModel = new DiscussionModel();
      $Discussion = $DiscussionModel->GetID($ID);
      $Sender->Permission('Vanilla.Discussions.View', TRUE, 'Category', $Discussion->PermissionCategoryID);
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Answers

  • hgtonighthgtonight MVP
    Answer ✓

    Yes. It is possible, but might get a little messy. You would have to validate permissions to view each discussion that has a tag and filter the results in the module.

    Something like this will get you started:

      // Loop through the IDs in the tagging 
      $DiscussionModel = new DiscussionModel();
      $Discussion = $DiscussionModel->GetID($ID);
      $Sender->Permission('Vanilla.Discussions.View', TRUE, 'Category', $Discussion->PermissionCategoryID);
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Just implemented this on our forum, these are the changes i made; (Not sure how fast it is on sites with many many discussions and tags)

    +++ /var/www/plott_forum/plugins/Tagging/class.tagmodule.php    2013-09-24 09:45:47.000000000 +0200
    @@ -23,18 +23,28 @@
           $SQL = Gdn::SQL();
           if (is_numeric($DiscussionID) && $DiscussionID > 0) {
              $this->_DiscussionID = $DiscussionID;
    -         $SQL->Join('TagDiscussion td', 't.TagID = td.TagID')
    -            ->Where('td.DiscussionID', $DiscussionID);
    +          $this->_TagData = $SQL                     
    +            ->Join('TagDiscussion td', 't.TagID = td.TagID')
    +            ->From('Tag t')
    +            ->Select('t.*')                 
    +            ->Where('td.DiscussionID', $DiscussionID)                 
    +            ->OrderBy('t.CountDiscussions', 'desc')  
    +            ->Limit(25)                 
    +            ->Get();               
           } else {
    -         $SQL->Where('t.CountDiscussions >', 0, FALSE);
    -      }
    -            
    -      $this->_TagData = $SQL
    -         ->Select('t.*')
    -         ->From('Tag t')
    -         ->OrderBy('t.CountDiscussions', 'desc')
    -         ->Limit(25)
    -         ->Get();
    +            $permArray = Gdn::Session()->GetPermissions(); // Permissions of currently logged in user
    +            $this->_TagData = $SQL            
    +                ->Join('TagDiscussion td', 't.TagID = td.TagID')
    +                ->Join('Discussion disc', 'disc.DiscussionID = td.DiscussionID')
    +                ->Join('Category cat', 'cat.CategoryID = disc.CategoryID')
    +                ->From('Tag t')                
    +                ->Select('t.*, count(td.TagID) as CountDiscussions')                        
    +                ->WhereIn('cat.PermissionCategoryID', $permArray['Vanilla.Discussions.View'], FALSE)
    +                ->GroupBy('td.TagID')
    +                ->OrderBy('CountDiscussions', 'desc')
    +                ->Limit(25)                    
    +                ->Get();
    +      }            
        }
    
        public function AssetTarget() {
    
Sign In or Register to comment.