Hi,
I'd like to request for a way to show what the user voted on a node, in his comments if he posts any.
Until it's properly implemented, I've done a nasty hack that would do it (it's nasty...) for anyone who's interested.
In your template.php file, add the following function (without the <?php opening and closing tags, i just put them here to make it look better )
<?php
/**
* function to get the voting result the user did, to display it in his comments.
*
* @param $content_type
* A string identifying the type of content whose votes are being retrieved. Node, comment, aggregator item, etc.
* @param $content_id
* The key ID of the content whose votes are being retrieved.
* @param $value_type
* An optional int representing the type of value saved in the vote. Three standard types are defined by votingapi:
* 'percent' -- 'Value' is a number from 0-100. The API will cache an average for all votes.
* 'points' -- 'Value' is a positive or negative int. The API will cache the sum of all votes.
* 'option' -- 'Value' is an int representing a specific option. The API will cache a vote-count for each option.
* @param $tag
* A string to separate multiple voting criteria. For example, a voting system that rates software for 'stability'
* and 'features' would cast two votes, each with a different tag. If none is specified, the default 'vote' tag is used.
* @param $uid
* An integer that is the user's ID
* @return
* A single voting result value, which is the percentage for the stars.
*/
function get_user_vote_result($content_type, $content_id, $value_type, $tag, $uid) {
$result = db_query("
SELECT value FROM {votingapi_vote} v
WHERE v.content_type='%s'
AND v.content_id=%d
AND v.value_type='%s'
AND v.tag='%s'
AND v.uid=%d",
$content_type, $content_id, $value_type, $tag, $uid);
while ($res = db_result($result)) {
return $res;
}
return 0;
}?>
Then, in your comment.tpl.php, add the following to display it.
<?php
// get the stars for the user
$user_result = get_user_vote_result('node', $comment->nid, 'percent', 'vote', $comment->uid );
print '<div class="fivestar-homepage">' . theme_fivestar_static($user_result, 5) .'</div>';
?>
Comments
Comment #1
captcha commentedThis would be a nice feature.
This post gives me the related idea that it would be very useful to have the user rating pre-loaded for the node while posting a comment, in case previously rated. This way, the user will not to have to re-rate a node for every comment posted on that node.
Right now, if the user has rated a node and comments on it, the rating is lost unless s/he specifies a rating again.
Comment #2
quicksketchI'd much rather take the approach captcha suggests as it's more intuitive to me. It'd be a simpler change too.
Comment #3
Anonymous (not verified) commented+1 for captchas approach.
Tracking this for solutions as I am very interested in this feature.
txcrew
Comment #4
quicksketchImplemented the suggestion in #1.
http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/fivestar/fi...
Comment #5
captcha commentedExcellent, will have to try it in the next release.
Comment #6
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.