• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Duplicate Poll results percentage incorrect if multiple votes allowed


Well-known member

When the option to allow more than 1 vote per user is set, the poll results in percentage are wrong.

This is due to the fact that you make the following computation in templates:
{xen:number {xen:calc "100 * {$response.response_vote_count} / {$poll.voter_count}"}, 1}%
while your voter_count is using uniquer users.

I did a quick not optimized fix by adding the following to the preparePoll function before the return:
if ($poll['max_votes'] > 1)
    $votesCount = 0;
    foreach($poll['responses'] AS $response)
        $votesCount += $response['response_vote_count'];
    $poll['voter_count'] = $votesCount;
But I am pretty sure you'll have a cleaner way ;)