Duplicate Poll results percentage incorrect if multiple votes allowed

XFA

Well-known member
Hi,

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:
HTML:
{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:
PHP:
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 ;)

Clément
 
Back
Top Bottom