2

I need to create a rule to change info of a user when this user is granted with points using the http://drupal.org/project/userpoints module.

I need the rule to have a condition and action like:

if total points of the user are greater than 1000 --> then set the field passed to 1

The field passed is a field that I added at admin/config/people/accounts/fields

My problem is that I can't load the Total points of the user in the conditions of the rule

I already have the userpoints_contrib module enabled.

1

3 Answers 3

1

I think that was added recently in dev: drupal.org/node/1109992

0

In the condition of your rule add Execute custom PHP code. Then add the following code to get total userpoints and check condition:

$current_points = userpoints_get_current_points($userpoints_transaction->uid, 'all');
if ($current_points >= 1000) {
  return true;
}

For more information about userpoints_get_current_points refer to this page

0

Apart from what's mentioned in the previous answers, there is also the Rules Action "Load user points of a user", whereas you can ask for either a specific category, or for all categories together. This Rules Action provides a Rules variable (for which you can specify its name and description) which contains the amount of user points for the requested category. You can then use this variable in subsequent Rules Actions.

If you then want to use that variable within a Rules Condition, you have 2 ways of doing so:

  • Include the condition in a Rules Component, whereas you trigger the execution of that Rules Component via a Rules Action following the "Load user points of a user" (and passing the variable containing the amount of user points as a variable for the Rules Component).
  • Use the Conditional Rules module, so that you can specify Rules Conditions within Rules Actions.

Here is a basic example that displays a message about the current total user points for a user (change the Rules Event to any Rules Event that you want):

{ "rules_display_userpoints_after_updating_content" : {
    "LABEL" : "Display userpoints after updating content",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "userpoints_rules", "rules" ],
    "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" } }
        }
      },
      { "drupal_message" : { "message" : "You now have [total-points:value] points" } }
    ]
  }
}

Use the Rules UI to import the above rule in your own site if you want.

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.