2

I have no access from Rules to [points] field or any userpoints field (User points module).

I have enabled: Rules, Rules scheduled, Rules_ui, Userpoints, Userponints_rules_integration, Userpoints_role (from userpoints_contrib),

I have done un/installed several times one by one modules mentioned with clear cache and cron in between and nothing, no access to userponits fields.

My event is "before saving content", in the Rules Conditions I have "User has a role-->auth-user", also in Rules Conditions I have "content is of type-->My custom contentype" in that order (I have changed that order with no results).

I need to update userponits field value before (preferred) or after a node is saved.

I tried also via Rules Components with an element "User has a role-->auth-user", same thing: no access to Userpoints fields.

I have another rule applied and reacting on Rules Event: “After saving a new user account” and there YES I have access to those fields.

Any ideas? Reference module? Do I have to implement a hook in template file to load current user? Do I need a custom module? I've seen all the node.one screencasts about Rules several times. And I have read many post in here, and (think) I’ve done everything right, but no success.

Any suggestions?

In case that your suggestions are: hook or module (I’m not a skilled programmer) please submit some code within.

4
  • I enebeled also rules bonus pack (Miscellaneous module) and it did nor work either.
    – pinueve
    Feb 3, 2015 at 2:52
  • Merci for the "accept"! Next question? Sep 5, 2016 at 18:59
  • Thank you Pierre, no questions at the moment, have a nice day, best regards from Mexico
    – pinueve
    Sep 5, 2016 at 19:01
  • OK, maybe in the near future then ... Similar regards from the land-that-Drupal-originates from (aka BE) ... Sep 5, 2016 at 19:05

1 Answer 1

1

There doesn't seem to be some Rules Condition related to the current total user points for a user. Except by using custom PHP code as in this example (which you could use in a Rules Conditionn Execute custom PHP code condition, e.g. to do some type of comparison):

global $user;
$current_points = userpoints_get_current_points($user->uid, 'all');
if ($current_points < 0) {return TRUE;}

However, there is a 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, after the user performed an update of some node (= the Rules Event, which you can change 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" : { "node_update" : [] },
    "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 that you have read and understand our privacy policy and code of conduct.

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