1

Can anyone provide me with a simple rule that adds 1 user point to a user when this user has viewed an entity of "Article" (for example)?

I have enabled the User Points module and the "Userpoints rules" integration module. But I can't find a way to get this to work.

1

Interesting question, worth to be considered as a great question for a Drupal site building exam!

Have a look at this rule:

{ "grant_user_points_after_content_view" : {
    "LABEL" : "Grant user points after content view",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "userpoints_rules" ],
    "ON" : { "node_view--article" : { "bundle" : "article" } },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "2" : "2" } }
        }
      }
    ],
    "DO" : [
      { "userpoints_action_grant_points" : {
          "user" : [ "site:current-user" ],
          "points" : "1",
          "tid" : "0",
          "entity" : [ "node" ],
          "description" : "View of node with id \u0022[node:nid]\u0022 and title \u0022[node:title]\u0022",
          "operation" : "NodeViewed",
          "reference" : "Viewing of [node:content-type] \u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E\/node\/[node:nid]\u003C\/a\u003E",
          "display" : "1",
          "moderate" : "default"
        }
      }
    ]
  }
}

Some details about this rule, which you should be able to import in your own site if you have the Rules UI, and Userpoints Rules (a sub-module of Userpoints), enabled and after you enable the rule also:

  • Rules Event: a Node of content "Article" is viewed (adapt the machine name of the used content type to any type that fits).
  • Rules Condition: user is authenticated (to be able to grant user points).
  • Rules Action: grant 1 point to the user viewing the article. And use some of the available tokens to add some more details to the actual User Points transaction (description, operation, reference) ... just for fun.

Easy, no? Sorry you had to wait for 2 years ...

PS: The previous answer is not really an answer to the question here I think.

  • Hello Pierre, Thanks for this but I cannot find the Userpoints Rules. That module does not seem to exist. Can you check your link please. Even after 2 years, still good! Ta! – BassPlaya Dec 5 '16 at 18:14
  • Awesome Pierre! It works! I gotta dig deeper into all the userpoint rules settings to get to the nitty-gritty! THANK YOU AGAIN! – BassPlaya Dec 6 '16 at 13:56
  • Apologies, I wasn't aware of clicking the 'tick'. Here you go ;-) – BassPlaya Dec 8 '16 at 6:08
0

If you are using variable module, then you can do it.

Please follow the steps:

  1. Provide a new variable (text type!), called Number, with the necessary PHP code (wrapped with <?php ... ?>). One can then use earlier calculated results like $mynumber.
  2. Convert Number to an integer, called Points.
  3. Grant Points to the user.

Hope this may help. Thank you.

  • I think the key thing is that the question asker wants to assign user points. This answer doesn't really address that. – rooby Nov 27 '14 at 5:23
  • @rooby: And now I have completely updated the answer. Please have a try. Thank you. – Ataboy Josef Nov 27 '14 at 5:40
  • Oops, that goes a bit beyond my knowledge but I'll try it. Thanks. – BassPlaya Dec 2 '14 at 12:02

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.