2

I want users on my sites to have badges assigned to them. I have user points,user badges, and rules module. User points is working fine. I have created a badge. Now I want that whenever a user's total points is greater than, say 50, he or she is assigned a badge. So, I went about to create a rule. However, I was not able to find any event, condition, or action for this. Please advice

Note: I tried to assign badges directly to users by going to their profiles and assigning them badges...however when i try to do so i get the following error:"My_Badge" is not a valid badge. Try using the autocomplete function (requires javascript). What is this?

  • I tried to assign badges directly to users by going to their profiles and assigning them badges...however when i try to do so i get the following error:"My_Badge" is not a valid badge. Try using the autocomplete function (requires javascript). What is this?Please advice – why Feb 25 '13 at 22:54
  • anyone ????????i have added this as an open issue for the module on drupal.org – why Feb 27 '13 at 20:25
0

This might not be an issue anymore, nevertheless, I think the problem should be solved now as the User Badges module has a production version out and most of the bugs have been taken care of. So, please upgrade to the latest 7.x-1.0 recommended release.

As for why you were not able to add a badge in your Rules action, well, the D7 version of User Badges was not integrated with Rules. We are actually working on it and it should be integrated very shortly.

0

Which version of User Badges are you using?

According to the module page "The 7.x version is NOT suitable for production yet." so if you want to use it you will probably need to do some manual debugging at the very least.

This user had the same issue you are seeing and they said uninstalling and reinstalling the latest 2.x dev worked for them.

  • i uninstall and then re-installed..still the error persists... – why Feb 26 '13 at 2:04
  • i am using the latest dev version – why Feb 26 '13 at 2:14
  • any ideas or hints? – why Feb 26 '13 at 2:28
0

Have a look at this Rules example (in Rules export format):

{ "rules_grant_a_new_badge" : {
    "LABEL" : "Grant a new badge",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "userpoints_rules", "rules", "user_badges", "rules_conditional" ],
    "ON" : { "userpoints_event_points_awarded_after" : [] },
    "DO" : [
      { "userpoints_rules_get_current_points" : {
          "USING" : { "user" : [ "site:current-user" ], "tid" : "all" },
          "PROVIDE" : { "loaded_points" : { "total_points" : "Number of points in all categories together" } }
        }
      },
      { "CONDITIONAL" : [
          {
            "IF" : { "NOT data_is" : { "data" : [ "total-points" ], "op" : "\u003C", "value" : "50" } },
            "DO" : [
              { "add_badge_by_name" : { "badge" : "1", "user" : [ "userpoints-transaction:user" ] } }
            ]
          }
        ]
      }
    ]
  }
}

It does retrieve, as the very first Rules Action (not Rules Condition!) the current amount of user points of a user. If the amount is at least 50, it will grant the user badge.

In this example I'm using the Conditional Rules module. By using this module, you can consolidate the logic for various user badges in a single rule, e.g bronze for 50 points, silver for 500 points, gold for 5000 points. Though you could also rework the Rules Action to performing Rules Components (in which you add the appropriate Rules Conditions), so that you don't need this extra module. For more details on that, refer to the answer to "What's the alternative to using the Conditional Rules module?".

The clue to make this rule work is the very first Rules Action "Load user points of a user". That's the alternative (work around?) for something like a missing Rules Condition to "check the current user points for a user".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.