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

Award a badge when posting in certain category

Hi @hgtonight‌,

Here I am again with another question/feedback topic.

Is it possible right now, to give out a badge when a visitor posts in a certain categorie? For instance, the introduce yourself categorie on our forums?

I think I havent seen that in the options list but I might be mistaken.

I also mistakenly took the award combo option for an option where you could select 2 badges, and let the system award a badge because of that "unlocked" combination. Might be a lot of work to program that in, and I'm not sure how often you'd use something like that. But maybe it can spark your imagination for your, already, massive to do list ;)

Comments

  • R_JR_J Admin
    edited May 2014

    @JanHoos said:
    Hi hgtonight‌,

    I also mistakenly took the award combo option for an option where you could select 2 badges, and let the system award a badge because of that "unlocked" combination. Might be a lot of work to program that in, and I'm not sure how often you'd use something like that. But maybe it can spark your imagination for your, already, massive to do list ;)

    You mean something like that? http://vanillaforums.org/badge/combo

  • Well, slightly like that.

    Instead I want to specify what awards someone must have, in order to unlock the combo award.

    I run an airsoft team so we have roles like squad member, squad leader and even commander. At this moment, I, or another admin, can give out manual badges for the before mentioned roles.

    When an individual played all the roles for instance, I want to give them an: "rising through the ranks" award. It would safe some time, and make the system more fool proof, if we can give the rising through the ranks badge automatically through a combo award.

    The ranks are not permanent in our team so we can run with different squad leaders every other day. So I want to promote people trying out squad leader or commander for a day so they can unlock the rising through the ranks combo badge.

    As I said in my opening post, this is more of a fine tuning situation. As its clearly possible to make the through the ranks badge a manual award :)

    But the posting in a specified categorie is something I would like to see, or someday try to build myself. But first, I'll try to see if I can hack my way in to a "pick 3 badges your proud of and show 'm off" plugin.

  • For posting in a category, copy the discussion body length rule, change the form to output a category list, validate should require an in, and check the submitted discussion's category against the criteria.

    Oh, and rename it to something else, like category post or something.

    As far as the badge combo, the UI would be the toughest thing to do there. Show a list of the current badges with checkboxes? That seems pretty meh. Any ideas?

    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.

  • Thanks for the points for the category award.

    hmmm good question. I was thinking about the checkboxes but I guess there would be a lot...

    Like I said, the combo award is something that I can fix by just going manual :)

  • R_JR_J Admin

    @hgtonight said:
    As far as the badge combo, the UI would be the toughest thing to do there. Show a list of the current badges with checkboxes? That seems pretty meh. Any ideas?

    I found that little js fiddle: http://jsfiddle.net/eUDRV/3/

    Maybe close to what is done there only that the input field below the right select box is replaced with a thumb of the selected badges?

  • Wauw @R_J‌ ! That would also be a good place to start with for a plugin where a visitor can select 3 of the badges they are most proud of, and want to display! :o

  • JanHoosJanHoos
    edited May 2014

    I've made the posting in a certain category badge <3

    I took the body length rule like you said @hgtonight‌, but made it so the user can manually input the id of the category. That can be found at the category edit page. I could not figure out how to load in categories from a pulldown menu so I went with this approach, as I knew I could be able to fix it this way.

    And of course added the definition's in English.

    Thanks for showing the way ^_^

    EDIT: I want to post the code but because of the ' characters in the code its not working.

  • You should use the code format under the paragraph button on the editor to post multi-line code. It will preserve format and escape html code so it looks right and is safe.

    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.

  • JanHoosJanHoos
    edited May 2014

    I was trying, but its not working for me on safari :(

    <?php if(!defined('APPLICATION')) exit();
    
    /**
     * This rule awards badges if a discussion is posted in the right category
     *
     * @author Zachary Doll
     * @since 1.0
     * @package Yaga
     */
    class DiscussionCategoryId implements YagaRule{
    
      public function Award($Sender, $User, $Criteria) {
        $Discussion = $Sender->EventArguments['Discussion'];
        $ID = ($Discussion->CategoryID);
    
        if($ID == $Criteria->ID) {
          return $Discussion->InsertUserID;
        }
        else {
          return FALSE;
        }
      }
    
      public function Form($Form) {
        $String = $Form->Label('Yaga.Rules.DiscussionCategoryId.Criteria.Head', 'DiscussionCategoryId');
        $String .= $Form->Textbox('ID', array('class' => 'SmallInput'));
        return $String;
      }
    
      public function Validate($Criteria, $Form) {
        $Validation = new Gdn_Validation();
        $Validation->ApplyRules(array(
            array(
              'Name' => 'ID', 'Validation' => array('Required', 'Integer')
            )
        ));
        $Validation->Validate($Criteria);
        $Form->SetValidationResults($Validation->Results());
      }
    
      public function Hooks() {
        return array('DiscussionModel_AfterSaveDiscussion');
      }
    
      public function Description() {
        $Description = sprintf(T('Yaga.Rules.DiscussionCategoryId.Desc'), C('Vanilla.Comment.MaxLength'));
        return Wrap($Description, 'div', array('class' => 'InfoMessage'));
      }
    
      public function Name() {
        return T('Yaga.Rules.DiscussionCategoryId');
      }
    
      public function Interacts() {
        return FALSE;
      }
    }
    
  • hgtonighthgtonight MVP
    edited May 2014

    You can get the categories into a pull down with the following snippet:

    $String = $Form->Label('Yaga.Rules.DiscussionCategoryId.Criteria.Head', 'DiscussionCategoryId');
    $String .= $Form->CategoryDropDown('CategoryID');
    return $String;
    

    Then the selected category ID will be in $Criteria->CategoryID.

    EDIT - Be sure to change the author credits to you!

    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.

  • Oh wauw! Its that simple haha! That looks a lot like the way Wordpress handles things! :o

    Well, if you want me to change it so you are not associated with it then I will. But I did not want to steal credit as its 90% your code ^_^

  • @JanHoos said:
    Oh wauw! Its that simple haha! That looks a lot like the way Wordpress handles things! :o

    Working with the Garden framework is really great, not going to lie.

    @JanHoos said:
    Well, if you want me to change it so you are not associated with it then I will. But I did not want to steal credit as its 90% your code ^_^

    I didn't mean it like that. I love collaborative works! Your idea, your implementation, your credit. :D

    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.

  • haha cool :) I'll change it right now together with your addition. Thanks again!

  • JanHoosJanHoos
    edited May 2014

    It worked! I had to change the validation process a bit, you sly dog @hgtonight‌ ;)

    Heres how it looks for the admin:

    And heres the final code (EDIT: Sorry... not sure how you fixed the above code insert :( :

    <?php if(!defined('APPLICATION')) exit();
    
    /**
     * This rule awards badges if a discussion is posted in the right category
     *
     * @author Jan Hoos
     * @since 2.1
     * @package Yaga
     */
    class DiscussionCategoryId implements YagaRule{
    
      public function Award($Sender, $User, $Criteria) {
        $Discussion = $Sender->EventArguments['Discussion'];
        $ID = ($Discussion->CategoryID);
    
        if($ID == $Criteria->CategoryID) {
          return $Discussion->InsertUserID;
        }
        else {
          return FALSE;
        }
      }
    
      public function Form($Form) {
        $String = $Form->Label('Yaga.Rules.DiscussionCategoryId.Criteria.Head', 'DiscussionCategoryId');
        $String .= $Form->CategoryDropDown('CategoryID');
        return $String;
      }
    
      public function Validate($Criteria, $Form) {
        $Validation = new Gdn_Validation();
        $Validation->ApplyRules(array(
            array(
              'Name' => 'CategoryID', 'Validation' => array('Required', 'Integer')
            ),
    
        ));
        $Validation->Validate($Criteria);
        $Form->SetValidationResults($Validation->Results());
      }
    
      public function Hooks() {
        return array('DiscussionModel_AfterSaveDiscussion');
      }
    
      public function Description() {
        $Description = sprintf(T('Yaga.Rules.DiscussionCategoryId.Desc'), C('Vanilla.Comment.MaxLength'));
        return Wrap($Description, 'div', array('class' => 'InfoMessage'));
      }
    
      public function Name() {
        return T('Yaga.Rules.DiscussionCategoryId');
      }
    
      public function Interacts() {
        return FALSE;
      }
    }
    
  • hgtonighthgtonight MVP
    edited May 2014

    Awesome!

    If you want me to include it in the next Yaga release, let me know what all the translation definitions are and I will sneak it in there.

    EDIT - If you are a GitHub users, feel free to submit a PR. What is GitHub?

    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.

  • JanHoosJanHoos
    edited May 2014

    Sure! That would be awesome :)

    $Definition['Yaga.Rules.DiscussionCategoryId'] = 'Post in category';
    $Definition['Yaga.Rules.DiscussionCategoryId.Desc'] = 'Award this badge if the user has started a discussion in the specified category.';
    $Definition['Yaga.Rules.DiscussionCategoryId.Criteria.Head'] = 'Select category:';
    
  • 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.

Sign In or Register to comment.