I saw the post Add user points for every upvote But that was for rewarding the voter, I want to reward the author like Reddit karma. Does anyone know how to do this with Rules? Vote integration for rules is installed of course
-
What have you tried already? It should not be much different from the link you provided.– 2phaFeb 22, 2015 at 9:14
-
The provided link awards the voter, not the author who's content received the vote it looks like.– Ed523Feb 22, 2015 at 19:40
-
Confirmed. the person who did the voting gets the points– Ed523Feb 22, 2015 at 19:58
-
Never mind, figured it out. you would change "user" : [ "vote:user" ]. to "user" : [ "node-author" ],– Ed523Feb 22, 2015 at 22:06
1 Answer
I recommend to go for a combination of these often used modules to add (or subtract) user points when some node is voted up (or down):
- Voting API.
- Rules.
- Voting Rules (attention: alfa version only).
- User Points.
It's also the approach used in the Answers module (disclosure: I'm a co-maintainer of it), i.e. within its submodule "Answers Userpoints". If you agree, read on ...
Required Rules
To handle all variations of voting, you need 4 rules (only!), which cover these 4 cases:
- a node is upvoted.
- an upvote for a node is canceled (= no longer upvoted).
- a node is downvoted.
- a downvote for a node is canceled (= no longer downvoted).
Below are the required rules, for each of these cases (use the Rules UI to import them in your own site, after you enabled the required modules mentioned above). These rules are enhanced versions of the rules included in the 7.x-4.0-rc2 version of Answers (and are expected to be committed to its dev version also). They use a content type with machine name answers_question
(adapt this name to fit your own machine name).
Have a close look at how user points are added (or subtracted), and also who gains (or looses) those points. Obviously, then actual amounts of userpoints can be adapted in those rules to fit your own needs.
Upvote a node
The rule below will grant +5 user points for an upvote (to the author of the node):
{ "rules_voteup_question" : {
"LABEL" : "voteup_question",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "answers" ],
"REQUIRES" : [ "rules", "voting_rules", "userpoints_rules" ],
"ON" : { "voting_rules_insert_node" : [] },
"IF" : [
{ "node_is_of_type" : {
"node" : [ "node" ],
"type" : { "value" : { "answers_question" : "answers_question" } }
}
},
{ "voting_rules_condition_check_vote_value" : { "vote" : [ "vote" ], "value" : "1" } }
],
"DO" : [
{ "userpoints_action_grant_points" : {
"user" : [ "node:author" ],
"points" : "5",
"tid" : "0",
"entity" : [ "" ],
"description" : "Receive upvote to [node:type-name] \u0022[node:title]\u0022",
"operation" : "QuestionUpvoteReceived",
"reference" : "By uid=[vote:uid], for [node:type-name] to q=\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E[node:title]\u003C\/a\u003E",
"display" : "1",
"moderate" : "default"
}
}
]
}
}
Cancel the upvote a node
The rule below will grant -5 (= remove +5) user points for a cancelled upvote (to the author of the node):
{ "rules_voteup_question_cancel" : {
"LABEL" : "voteup_question_cancel",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "answers" ],
"REQUIRES" : [ "rules", "voting_rules", "userpoints_rules" ],
"ON" : { "voting_rules_delete_node" : [] },
"IF" : [
{ "node_is_of_type" : {
"node" : [ "node" ],
"type" : { "value" : { "answers_question" : "answers_question" } }
}
},
{ "voting_rules_condition_check_vote_value" : { "vote" : [ "vote" ], "value" : "1" } }
],
"DO" : [
{ "userpoints_action_grant_points" : {
"user" : [ "node:author" ],
"points" : "-5",
"tid" : "0",
"entity" : [ "" ],
"description" : "Unupvote [node:type-name] \u0022[node:title]\u0022",
"operation" : "QuestionUpvoteCancelled",
"reference" : "By uid=[vote:uid], for [node:type-name] to q=\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E[node:title]\u003C\/a\u003E",
"display" : "1",
"moderate" : "default"
}
}
]
}
}
Downvote a node
The rule below will subtract -2 (grant -2) user points for a downvote (to the author of the node) ... AND also -1 user point for the voter:
{ "rules_votedown_question" : {
"LABEL" : "votedown_question",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "answers" ],
"REQUIRES" : [ "rules", "voting_rules", "userpoints_rules" ],
"ON" : { "voting_rules_insert_node" : [] },
"IF" : [
{ "node_is_of_type" : {
"node" : [ "node" ],
"type" : { "value" : { "answers_question" : "answers_question" } }
}
},
{ "voting_rules_condition_check_vote_value" : { "vote" : [ "vote" ], "value" : "-1" } }
],
"DO" : [
{ "userpoints_action_grant_points" : {
"user" : [ "node:author" ],
"points" : "-2",
"tid" : "0",
"entity" : [ "" ],
"description" : "Receive downvote to [node:type-name] \u0022[node:title]\u0022",
"operation" : "QuestionDownvoteReceived",
"reference" : "By uid=[vote:uid], for [node:type-name] to q=\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E[node:title]\u003C\/a\u003E",
"display" : "1",
"moderate" : "default"
}
},
{ "userpoints_action_grant_points" : {
"user" : [ "vote:user" ],
"points" : "-1",
"tid" : "0",
"entity" : [ "" ],
"description" : "Issue downvote to [node:type-name] \u0022[node:title]\u0022",
"operation" : "QuestionDownvoteIssued",
"reference" : "From uid=[node:author:uid], for [node:type-name] to q=\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E[node:title]\u003C\/a\u003E",
"display" : "1",
"moderate" : "default"
}
}
]
}
}
Cancel the downvote a node
The rule below will grant +2 (= remove -2) user points for a cancelled downvote (to the author of the node) ... AND also +1 user point for the voter:
{ "rules_votedown_question_cancel" : {
"LABEL" : "votedown_question_cancel",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "answers" ],
"REQUIRES" : [ "rules", "voting_rules", "userpoints_rules" ],
"ON" : { "voting_rules_delete_node" : [] },
"IF" : [
{ "node_is_of_type" : {
"node" : [ "node" ],
"type" : { "value" : { "answers_question" : "answers_question" } }
}
},
{ "voting_rules_condition_check_vote_value" : { "vote" : [ "vote" ], "value" : "-1" } }
],
"DO" : [
{ "userpoints_action_grant_points" : {
"user" : [ "node:author" ],
"points" : "2",
"tid" : "0",
"entity" : [ "" ],
"description" : "Cancel downvote to [node:type-name] \u0022[node:title]\u0022",
"operation" : "QuestionDownvoteCancelled",
"reference" : "By uid=[vote:uid], for [node:type-name] to q=\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E[node:title]\u003C\/a\u003E",
"display" : "1",
"moderate" : "default"
}
},
{ "userpoints_action_grant_points" : {
"user" : [ "vote:user" ],
"points" : "1",
"tid" : "0",
"entity" : [ "" ],
"description" : "Withdraw downvote to [node:type-name] \u0022[node:title]\u0022",
"operation" : "QuestionDownvoteWithdrawn",
"reference" : "From uid=[node:author:uid], for [node:type-name] to q=\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E[node:title]\u003C\/a\u003E",
"display" : "1",
"moderate" : "default"
}
}
]
}
}