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');
        }
      }
?>

AttachmentSize
vote_up_down.module-vote_karma-patch.txt1.22 KB

#1

ola90@drupal.ru - August 24, 2007 - 06:15

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

Gregory Go - September 4, 2007 - 09:29

ola90, you're absolutely right. Thanks!

I took your code from http://drupal.org/node/101791, added configurable userpoints multipler and rolled another patch.

AttachmentSize
vote_up_down.module-userpoints_for_content_rating-5.patch 2.61 KB

#3

stevepurkiss - September 5, 2007 - 14:37

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

stevepurkiss - July 9, 2008 - 16:21
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

Prodigy - August 9, 2008 - 21:44

Any updates on this?

#6

Gekiboy - June 30, 2009 - 22:14
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.

AttachmentSize
vote_up_down.module.patch 2.31 KB

#7

Gekiboy - July 17, 2009 - 23:12

Recreated the patch using CVS instead of SVN incase that matters

AttachmentSize
vote_up_down-170068.patch 2.79 KB

#8

mrwhizkid - September 3, 2009 - 16:18

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

ingo86 - September 6, 2009 - 13:47
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

ingo86 - September 6, 2009 - 13:47
Status:needs review» by design
 
 

Drupal is a registered trademark of Dries Buytaert.