Add/subtract userpoints for content author based on vote
Gregory Go - August 24, 2007 - 05:48
| Project: | Vote Up/Down |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | ingo86 |
| Status: | by design |
Description
Sometimes known as "karma". In our case, we wanted storylink submitters to get more/less userpoints when someone up/down votes their submissions.
Described in this feature request for 4.7: http://drupal.org/node/101791
The attached patch adds to two functions:
1. vote_up_down_userpoints()
Adds an additional field at admin/settings/userpoints in the vote_up_down fieldset:
<?php
$form['vote_updown_points']['userpoints_vote_up_down_karma'] = array(
'#type' => 'textfield',
'#title' => t('Points resulting from vote on a node user authored (requires the Vote up/down module)'),
'#default_value' => variable_get('userpoints_vote_up_down_karma', 0),
'#size' => 5,
'#maxlength' => 5,
);
?>2. vote_up_down_vote()
In the userpoints integration section... after giving the voter a userpoint, give the author a userpoint.
<?php
// update userpoints based on the vote value
if ($vote->value != 0) {
if ( variable_get('userpoints_vote_up_down_karma', 0) ) {
userpoints_userpointsapi('points', ($vote->value * variable_get('userpoints_vote_up_down_karma', 0)), $node->uid, 'Vote up/down karma');
}
}
?>| Attachment | Size |
|---|---|
| vote_up_down.module-vote_karma-patch.txt | 1.22 KB |

#1
How does this code handle the case when a user first votes "up" and then changes his mind and votes "down"? It looks like author's karma will be reset to 0 while his node will have a negative score.
#2
ola90, you're absolutely right. Thanks!
I took your code from http://drupal.org/node/101791, added configurable userpoints multipler and rolled another patch.
#3
OMG, thanks so much for fixing that - was trying to figure this one out but it was making my brain hurt!
fyi - if you enable 'reset vote' it doesn't reset the points, but in my case I'm not going to enable that, just thought you might like to know...
#4
Just been wrapping my head around why this wasn't working as I had it working fine before - it's because the userpoints api has changed so now you need to pass an array of values:
http://drupal.org/node/206558
e.g.
$params = array (
'uid' => $node->uid,
'points' => ($vote->value * variable_get('userpoints_vote_up_down_content_rating', 0)),
'description' => 'Vote up/down karma',
);
userpoints_userpointsapi($params);
instead of:
userpoints_userpointsapi('points', ($vote->value * variable_get('userpoints_vote_up_down_content_rating', 0)), $node->uid, 'Vote up/down karma');
...so in other words, these patches don't work at the moment with the latest userpoints
#5
Any updates on this?
#6
This, and other code in this module around the userpoints system is broken. As this module uses the votingapi module, all userpoint functionality base on voting should be taken care of by the userpoints_votingapi anyway. I am proposing this patch to remove the traces of userpoints functionality from this module as it is only detrimental at this point.
#7
Recreated the patch using CVS instead of SVN incase that matters
#8
I am trying to follow this thread and I am confused. Is there a way in Drupal 6 to give points to the author when his/her node is voted up? Or the other way around?
#9
This thing is absolutely out of the range of features of vote up down.
This is just a voting module that interfaces with voting_api. Nothing else.
For what you need, I developed as part of this year google Summer of Code a set of modules that do just what you require. Everything is interfaced with user_karma. If you wanna taka a look go here:
http://drupal.org/project/peerreview
Everything needs work but the code should be good, for your needs you have to enable the user_karma plugin.
#10