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.

Displaying Ranks in Posts & User Profile

Before my question: Yaga is awesome. It is a dealmaker for my site deploying Vanilla. Thank you so much for this addon! I really like Ranks, and will be using them to structure our guild.

The Question: How can we display ranks on user profiles and, more importantly, posts (similar to the MyYagaPoints or YagaDiscussionHeaderBadges plugins)?

Tagged:

Comments

  • hgtonighthgtonight ∞ · New Moderator

    Thanks for trying my addon!

    You can get the RankID from the User object. From there, you can get a list of the ranks from the rank model. A rough sketch of how to do this via a plugin would be as follows:

    public function DiscussionController_AuthorInfo_Handler($Sender) {
      $Author = $Sender->EventArguments['Author'];
      $RankID = $Author->RankID;
      $RankModel = Yaga::RankModel();
      $Rank = $RankModel->GetByID($RankID);
      echo WrapIf($Rank->Name, 'span', array('class' => 'Rank Rank-' . $RankID));  
    }
    

    It would probably be a good idea to cache the rank list locally and just traverse the dataset to reduce db reads per page.

    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.

  • It would probably be a good idea to cache the rank list locally

    an example is worth a thousand words if you got the time :)

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

  • hgtonighthgtonight ∞ · New Moderator
    edited June 2014

    @peregrine said:

    It would probably be a good idea to cache the rank list locally

    an example is worth a thousand words if you got the time :)

    I actually misspoke slightly. I meant use the cached rank list and traverse locally. Something like the following:

    public function DiscussionController_AuthorInfo_Handler($Sender) {
      $Author = $Sender->EventArguments['Author'];
      $RankID = $Author->RankID;
      $RankModel = Yaga::RankModel(); // Gets the already instantiated model
      $Ranks = $RankModel->Get(); // Gets the cached rank list or sets the cache with a db read
    
      $AuthorRank = new stdClass();
      $AuthorRank->Name = NULL;
      foreach($Ranks as $Rank) {
        if($Rank->RankID == $RankID) {
          $AuthorRank = $Rank;
          break;
        }
      }
    
      echo WrapIf($AuthorRank->Name, 'span', array('class' => 'Rank Rank-' . $RankID));
    }
    

    I might add a method returning a cached array indexed by ID of badges, ranks, and actions in their respective models. Definitely make writing plugins easier. Any DB gurus want to chime in?

    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.

  • @hgtonight‌ how i cant show the ranks in the comments too, becouse i can only see in the 1st post

  • hgtonighthgtonight ∞ · New Moderator

    @multplaneta‌ I am seeing ranks on all comments and in the first post.

    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.

  • hgtonighthgtonight ∞ · New Moderator

    @phyroxis‌ Just wanted to let you know that I packaged this as a plugin here: http://vanillaforums.org/addon/yagarankinmeta-plugin

    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.

  • @hgtonight‌ Thanks for the quick reply, for my only show in the first post, maybe i do something wrong, i will try your Rank in Meta Plugin.

  • hgtonighthgtonight ∞ · New Moderator

    @multplaneta said:
    hgtonight‌ Thanks for the quick reply, for my only show in the first post, maybe i do something wrong, i will try your Rank in Meta Plugin.

    What theme are you using?

    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.

  • @hgtonight‌ iam using Bootstrap version 2.2.2

  • @hgtonight‌ I test your plugin and work, now i can see in all posts, thanks!

Sign In or Register to comment.