Hi,

Lets say when a user votes he/she receives 5 points and the author receives 10 points.
Now, I thinking how to award an author with a bonus (say 100 pts) after receiving 100 votes.

a) One way to write a module that implements hook_votingapi_insert() and hook_votingapi_delete() that would replicate some of the logic, and count (in a table) the votes an author receives.
(userpoints_votingapi.module could also be hacked, but we want to avoid that).

b) Another idea was to look in the userpoints_txn table and add up the votes received for a uid (perhaps via a rule). But there is no distinction there between the voter and author.

Questions:
- what strategy would you suggest?
- If b) above, could userpoints_votingapi so that use transaction has something init to differentiate between the user and author votes? Perhaps in the description part of the transaction prefix "Vote receive" for authors and "Vote: cast" for users (e.g. around lines 105 and 140 of userpoints_votingapi.module) . Or change the operations to vote and votereceive?

Thanks in advance,

Comments

boran’s picture

Title: Awarding additional points after an author reveives say 100 votes » Awarding additional points after an author receives say 100 votes
boran’s picture

Category: support » feature
Status: Active » Needs review

I went ahead and implemented plan b).
diff userpoints_votingapi.module userpoints_votingapi.module.orig:

137c137
<         'operation' => t('voteauthor'),
---
>         'operation' => t('vote'),
139c139
<         'description' => t('Vote receive: !content_type !content_id.', array('!content_type' => $vote['content_type'], '!content_id' => $vote['content_id'])),
---
>         'description' => t('Vote cast: !content_type !content_id.', array('!content_type' => $vote['content_type'], '!content_id' => $vote['content_id'])),
198c198
<         'operation' => t('voteauthor'),
---
>         'operation' => t('vote'),
210c210
< }
---
> }

Then in my module I've a function to check the points total for an author:

function userpoints_visits_authorpoints($uid) {
  $number = db_result(db_query("select sum(points) FROM {userpoints_txn} WHERE operation = 'voteauthor' AND uid = %d", $uid));
  return ($number);
}

So the question is whether the userpoints_votingapi code change above can be integrated into the official release? It is of general use, of little rish and perhaps useful for others?

Thanks in advance.