3

I'm using the User Points module which allow me to grant points to user. So far so good.

I need to create a rule to fire this condition/action: When user points are granted, then check if the user has more than 10 points. If so then add the "Master" role to this user.

I try using the Rules Condition "Data comparison", but I can't find the value something like "total points of the user".

Can I do this in any way?

2 Answers 2

3

Have you tried the user points contrib module. I am specifically referring to

userpoints_role

Users join/leave roles as they earn/lose certain points threshold.

1
  • I didn't know there was a contrib module to do this. This is great.
    – chefnelone
    Commented Dec 19, 2012 at 18:47
1

Your question is about using Rules and find '... something like "total points of the user" ...' (and related to Rules Event "When user points are granted to a user"). So have a look at this Rules example (in Rules export format):

{ "rules_grant_new_role" : {
    "LABEL" : "Grant a new role",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "userpoints_rules", "rules", "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" : "11" } },
            "DO" : [
              { "drupal_message" : { "message" : "You have at least 11 points (actually you have [total-points:value] points ...)." } }
            ]
          }
        ]
      }
    ]
  }
}

The above rule 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 11, it will show an appropriate message about that (just replace that with a Rules Action to grant a role to fit your case).

In this example I'm using the Conditional Rules module, 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.

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 and acknowledge you have read our privacy policy.

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