How do I get the karma score, and only the karmascore to display on theme? This way I can make a check on the theme to process promote vs bury.

Comments

mercmobily’s picture

Status: Active » Fixed

Hi,

Please use the VotingAPI to do that.
For example:

$existing_vote_cast = votingapi_get_vote('node', $node->id, 'points', 'vote', $user->uid);

Bye,

Merc.

Flying Drupalist’s picture

Status: Fixed » Active

Thank you mercmobily, how would I adapt that to comments? Just changing node to comments seem to be insufficient.

$existing_vote_cast = votingapi_get_vote('comment', $comment->cid, 'points', 'vote', $user->uid);

I get this for instance: Fatal error: Call to undefined function votingapi_get_vote() in /home2/public_html/sites/all/themes/comment.tpl.php on line 16

mercmobily’s picture

Hi,

First of all, let me correct my piece of advice:

 $r = votingapi_get_voting_result('comment', $comment->cid, 'points', 'vote', 'sum');

This will work if you want the comment's total count.

(sorry about that)
But... it's _really_ strange that you're given an "undefined call" for votingapi_get_vote. I am not sure why it would happen -- you do have VotingAPI installed, certainly... right?

Merc.

Flying Drupalist’s picture

Hi thanks for your help. I'm getting a Fatal error: Call to undefined function votingapi_get_voting_result() in /home2/public_html/sites/all/themes/comment.tpl.php on line 2

I have votingapi installed of course, and EVF installed too :) And both works fine.

I'm probably doing something I'm not supposed to with your snippet. I just stuck it on top of my comment.tpl.php.

mercmobily’s picture

Hi,

Am I going to give away the fact that I am incompetent, if I answer "I have no idea why"?!? :-/

Merc.

mercmobily’s picture

Hi,

I'vee just added this to drigg's default comment template:

  $r = votingapi_get_voting_result('comment', $comment->cid, 'points', 'vote', 'sum');
  print "ehEheheh $r->value";

And it works...

Merc.

Flying Drupalist’s picture

If you're incompetent, what does that make me? :)

This is so strange. Does it perhaps have to do with the theme? I'm using Zen... Geh :(.

I'm going to try reinstalling votingapi/eaf and see if that helps.

mercmobily’s picture

Hi,

I don't think it will... but I really don't know what it could be.
And you would be surprised, how incompetent I can be. Don't underestimate yourself!

Merc.

Flying Drupalist’s picture

Thank you for your help merc. On IRC after a bit of tweaking merc found an example snippet that works:

 $r = votingapi_select_results( array('content_type'=>'comment', 'content_id' => $comment->cid, 'value_type' => 'points', 'tag' => 'vote', 'function' => 'sum') ); print "ehEheheh ". (int)$r[0]['value'];

Flying Drupalist’s picture

Status: Active » Fixed

*doh

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.