Vote Up/Down module allows user to gain points when ratting content, but I think it would be cool if user points are affected by other user rating of their posts and comments.

Let's say user A writes a forum topic. User B likes it and votes up. User B gains X points (as defined on userpoints module config) but that rating currently doesn't affect user A. Using my idea, after that vote is done user A will gain a point too.

This would work too for negative votes.

This way, the total amount of user points will be a reflect of how does the user collaborate on the community and what the community think about that user collaborations.

Thanks.

Comments

frjo’s picture

Assigned: Unassigned » frjo
Status: Active » Postponed

I'm doing something similar on vigillar.se, the voting action that moves post to the front page gives the author points. If the post later is demoted the points are removed.

Check out the "Award userpoint to node author (Vote up/down)" and "Deduct userpoint from node author (Vote up/down)" voting actions.

Will think about adding more functionality after the upgrade to Drupal 5 is done.

ola90@drupal.ru’s picture

I added a few lines to vote_up_down.module (function vote_up_down_vote) to do this:

    // Do the voting via voting api.
    if ($uid = _vote_up_down_get_uid()) {
      if ($vote->value == 0) {
        votingapi_unset_vote($type, $cid, $uid);
      }
      else
      global $user;
      if ($type == 'node') {$node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.uid FROM {node} n WHERE n.nid = %d'), $cid)); } else {$node = db_fetch_object(db_query(db_rewrite_sql('SELECT c.uid FROM {comments} c WHERE c.cid = %d'), $cid)); }
      {
	if (votingapi_get_user_votes($type, $cid, $user->uid)) {
        // we record the current rating of the node
	$vote_result = votingapi_get_voting_result($type, $cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum');
	$vote_old = $vote_result;
        // let the module do its work
        votingapi_set_vote($type, $cid, $vote, $uid);
        // get the new rating
	$vote_result = votingapi_get_voting_result($type, $cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum');
	$vote_new = $vote_result;
        // calculate the difference
	$diff->value = $vote_new->value - $vote_old->value;
        // and add/subtract the same number of userpoints
	userpoints_userpointsapi('points', $diff->value, $node->uid, 'content rated'); }
	else {
	votingapi_set_vote($type, $cid, $vote, $uid);
        // or, if it's the first time that user votes, just send the same vote to userpoints
	userpoints_userpointsapi('points', $vote->value, $node->uid, 'content rated'); }

Using this scheme solves the problem when user gives a node +1, then -1. vote_up_down will have that node rated -1, but if you send the same votes directly to userpoints, the result will be 0.

madjr’s picture

Does this code work with drupal 5.x ?

exactly what does it do ? can it really add/sub points from user to user ?

ola90@drupal.ru’s picture

Yes, it works on my test website under Drupal 5.1 and it does what it says. The site is in Russian, but you can check it out yourself by just pressing +/- buttons and checking out the content author's rating on his profile page. Login as "50squid" with password "massacre".

ola90@drupal.ru’s picture

oops, forgot about the URL. it's ola90.prohosts.org/drupal

Greg Go’s picture

Here's a patch for 5.x to do this. http://drupal.org/node/170068

Greg Go’s picture

Attached it the above code (more or less) in patch form for 4.7.

5.x version at http://drupal.org/node/170068#comment-299508

ingo86’s picture

Assigned: frjo » ingo86
Status: Postponed » Closed (won't fix)

Drupal 6 has the peer review project to do that.
However I don't think this is part of the project, which is just a vote up down module. I suggest an external plugin if needed.