Download & Extend

Add/subtract userpoints for content author based on vote

Project:Vote Up/Down
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:ingo86
Status:closed (works as designed)

Issue Summary

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');
        }
      }
?>
AttachmentSizeStatusTest resultOperations
vote_up_down.module-vote_karma-patch.txt1.22 KBIgnored: Check issue status.NoneNone

Comments

#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.

AttachmentSizeStatusTest resultOperations
vote_up_down.module-userpoints_for_content_rating-5.patch2.61 KBIgnored: Check issue status.NoneNone

#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

Status:needs review» needs work

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

Version:5.x-1.x-dev» 6.x-1.x-dev
Status:needs work» needs review

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.

AttachmentSizeStatusTest resultOperations
vote_up_down.module.patch2.31 KBIgnored: Check issue status.NoneNone

#7

Recreated the patch using CVS instead of SVN incase that matters

AttachmentSizeStatusTest resultOperations
vote_up_down-170068.patch2.79 KBIgnored: Check issue status.NoneNone

#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

Assigned to:Anonymous» ingo86

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

Status:needs review» closed (works as designed)

#11

Subscribe to read later