Hi,

This is not really a support request. I am the author of simple_karma, an idiotic module which used to have its own voting subsystem. I converted it to votingAPI, and am now developing a neat way of keeping track of the user's karma just by adding a few hooks.
I love your code, I think it's fantastically developed. It allowed me to do whatever I needed to do, quickly. I am in love with your code!

I have a couple of questions. Basically, I am assigning some karma automatically to a user when a comment or a node is voted upon. I hook to insert, update and delete. Everything is great.
This is what I get added when a person votes on a node through votingapi_set_vote():

+---------+--------------+------------+-------+--------------+--------------+------+------------+-----------+
| vote_id | content_type | content_id | value | value_type   | tag          | uid  | timestamp  | hostname  |
|     141 | user         |       1378 |    -1 | karma_points | karma-n-8527 |    1 | 1198232904 | 127.0.0.1 | 

The first hack-ish thing I do is set the tag to "karma-n-8527". The user voted on the node 8527. This really works, since if the user changes the vote for that node, votingapi_set_vote() will change this very record with the new vote.
Is this "ugly" Eaton?

The second "hack" is the cache calculating hook, which right now is:

function user_karma_votingapi_calculate(&$cache, $votes, $content_type, $content_id){

  if($content_type == 'user'){

  // Loop through, calculate per-type and per-tag totals, etc.
    foreach ($votes as $vote) {
      if($vote->value_type == 'karma_points'){
        $cache['karma'][$vote->value_type]['sum'] += $vote->value;
      }
    }
  }

}

The only thing that bothers me is that the tag for the cache doesn't correspond to the tag in the vote. However, this is important because after a few votes the cache table will hold:

+---------------+--------------+------------+-------+--------------+-------+----------+------------+
| vote_cache_id | content_type | content_id | value | value_type   | tag   | function | timestamp  |
+---------------+--------------+------------+-------+--------------+-------+----------+------------+
|           583 | user         |       1378 |     2 | karma_points | karma | sum      | 1198232941 | 

This person has received 4 karma points, +1 +1 -1 +1, so the result is 2.
Again, am I using your API outrageously?

Again, thanks a billion!!!

Merc.

Comments

mercmobily’s picture

Hi,

Please look at:

http://drupal.org/node/202944#comment-670014

The issue is solved and closed. I hope you like the way I solved it!

Merc.

eaton’s picture

Status: Active » Closed (won't fix)

Support for the 5.x branch of VotingAPI has ended with the release of Drupal 7 and the upcoming release of VotingAPI 7.x-2.4.