I am using advanced forum and the users have the option to vote on other peoples post and comments.

I would like to include a total votes received for each user in the author pane so that other users can see that this user has received [amount] of votes on their content. Like a small trust factor hopefully making the other users more curious to read a certain users post if he/she has received a large amount of votes.

I am not that familiar with PHP and MySQL commands for pulling the data direct from the database so hope somebody might be willing to help out unless there is a simpler way of doing this from the module itself or using views.

Comments

sbonde’s picture

I managed to get this working retrieving the data directly from the database, but think there might be a better way of doing this.

	$node_count = mysql_query(
		"SELECT COUNT(*) as node_count
		FROM votingapi_vote 
		INNER JOIN node ON votingapi_vote.content_id = node.nid
		WHERE content_type = 'node' AND value = '1' AND value_type = 'points' AND tag = 'vote' AND node.uid = $account->uid
		GROUP BY node.uid"
	); 
	while ($get_user_node_votes = db_fetch_object ($node_count)) {
	  $user_node_votes = $get_user_node_votes->node_count;
	}

	$comment_count = mysql_query(
		"SELECT COUNT(*) as comment_count
		FROM votingapi_vote 
		INNER JOIN comments ON votingapi_vote.content_id = comments.cid
		WHERE content_type = 'comment' AND value = '1' AND value_type = 'points' AND tag = 'vote' AND comments.uid = $account->uid
		GROUP BY comments.uid"
	); 
	while ($get_user_comment_votes = db_fetch_object ($comment_count)) {
	  $user_comment_votes = $get_user_comment_votes->comment_count;
	}

	print $user_node_votes + $user_comment_votes;

Since I need this on the users author pane I am afraid it might be a bit heavy requesting the data from the database about 30 times per forum post (forum post is set to 30 comments).

marvil07’s picture

Title: Get totalt count of votes cast on content create by user » Get total count of votes cast on content created by user
Category: feature » support

You should be able to do that with views. There you have optional cache too ;-)

sbonde’s picture

Can you please explain howto?
I can't seem to find out how to show the amount of votes on node/comments per user (where the user is the author of the node/comment that has received the vote).

grn’s picture

Yes, this feature would be nice. But maybe this should be posted at the voting api project?

I am looking to do the same thing. Create a user list that displays how many votes the content of the specific user has received. In addition it would be nice to see how many votes the user has received on the latest node or comment.

If you find any great solutions in CCK it would be great. I will try to get back to this thread if I find a solution.

I have been thinking about creating a CCK field on the user to capture total votes through a computed CCK field. I am using Drupal 7 though.

Thanks.

/GrN.dk

grn’s picture

I am trying to find the solutions through views: http://drupal.org/node/1848224

Please review that too. Maybe you will be able to help out with finding the solution.

Thanks.

/GrN.dk

marvil07’s picture

Project: Vote Up/Down » Voting API
Version: 6.x-3.2 » 7.x-2.9
Component: Miscellaneous » Views Integration

This is not specific of vote up down, so moving to voting api queue.

adriankremer’s picture

Issue summary: View changes

hi,

just translated #1 to db object method
the function also checks if a vote is done by a user or not

function get_voting_results(&$uid,$valid_results = false){
    $query = db_select('votingapi_vote','v');
    $query->innerjoin('node', 'n', 'v.entity_id = n.nid');
    $query->fields('v')
        ->condition('v.entity_type', 'node','=')
        ->condition('v.value', '1','=')
        ->condition('v.value_type', 'points','=')
        ->condition('n.uid', $uid,'=');
    if($valid_results == true){
        $query->fields('v')
            ->condition('v.uid', '0','!=');
    }
    $result = $query->execute();
    $total = $votes = '';
    while ($record = $result->fetchAssoc()) {
        $votes[] = $record;
    }
    foreach($votes as $vote){
        $total += $vote['value'];
    }
    return $total;
}