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.

Is there a way to hide/replace badges as users level up in the same category?

For instance the 2 year anniversary badge would replace the 1 year anniversary badge? It seems like in that case the 2 year anniversary badge would imply the 1 year so there would be no need to display it. My apologies if this question has already been answered elsewhere but i was unable to find it.

Comments

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    The Idea of badges, is to show all of the ones you have won through your participation. Like a badge of Honor. If you got a second badge of Honor, should you give back the first one ? A soldier goes to battle and gets a medal of Valor for that battle. Does a second medal of Valor imply that the first one has no more value ?

    If you don't want specific badges to show and if they have specific CSS classes, you can write some code to hide them from view via display:none ....

    Or you could modify the application to not show past badges, which your users might not like at all. Because earning or winning something is a reward for participating and if there is no reward you will lose interest from users.

    Why bother having an application like this if you take the whole game aspect out of it.

  • I kind of understand the philosophy behind the badge system but for like categories it starts to make my very active users look like a north Korean general. If everything is special than nothing is. Thanks for your help, that answers my question i guess.

  • R_JR_J Ex-Fanboy Munich Admin

    I see your point. But badges are not ranks. Ranks are replacing lower ranks. Badges still remain. I'm not sure if you would be able to a make a "this badge replaces that badge" logic, but I would also say that this doesn't feel right.

  • yeah, I'm seeing that. You would need some sort of anti-badge to remove existing badges once certain criteria were met or a way to check when a new badge was earned if an older badge was no longer needed. Oh well, thanks for your help. =)

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    I want my badges to look like North Korean leader.. what is wrong with that !!

  • hgtonighthgtonight ∞ · New Moderator
    edited August 2017

    @mickeybond said:
    yeah, I'm seeing that. You would need some sort of anti-badge to remove existing badges once certain criteria were met or a way to check when a new badge was earned if an older badge was no longer needed. Oh well, thanks for your help. =)

    You could do this fairly easily as a custom rule. Assuming you are talking about the Length Of Service rule, you could even extend the base rule to use the existing checking code and only remove other badges if a new one to be awarded.

    Something like:

    class HighlanderLoS extends LengthOfService
    {
      public function Award($Sender, $User, $Criteria)
      {
        if (parent::Award($Sender, $User, $Criteria))
        {
          // Get other badges using the same rule
          $BadgeAwardModel = Yaga::BadgeAwardModel();
          $Badges = $BadgeAwardModel->GetByUser($User->UserID);
          foreach($Badges as $Badge)
          {
            if($Badge->Enabled && $Badge->RuleClass == "HighlandLoS")
            {
              if (badgeIsTheBestBadge()) // you will have to implement this method
              {
                unaward($Badge, $User);
              }
            }
          }
          return true;
        }
      }
    
      // shamelessly taken from YagaUnawardBadge by @Bleistivt https://github.com/bleistivt/YagaUnawardBadge/blob/master/class.yagaunawardbadge.plugin.php
      private function unaward($badge, $user)
      {
        Gdn::sql()->delete('BadgeAward', ['BadgeAwardID' => $badge->BadgeAwardID], 1);
        Gdn::sql()
          ->update('User')
          ->set('CountBadges', 'CountBadges - 1', false)
          ->where('UserID', $badge->UserID)
          ->put();
    
        $points = Yaga::BadgeModel()->GetByID($badge->BadgeID)->AwardValue;
        Yaga::givePoints($badge->UserID, -1 * $points, 'Badge');
      }
    }
    

    This is untested and unfinished but should get you started.

    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.

  • R_JR_J Ex-Fanboy Munich Admin

    @hgtonight said:
    Something like:

    class HighlanderLoS extends LengthOfService
    

    :lol:

Sign In or Register to comment.