function advpoll_pooled_vote in Advanced Poll 7.2
Same name and namespace in other branches
- 7.3 includes/advpoll_voteapi.inc \advpoll_pooled_vote()
- 7 includes/advpoll_voteapi.inc \advpoll_pooled_vote()
Tally votes by pooling them. All votes, whether cast by single or multichoice bear the same weight.
Parameters
$results: Results returned from voting api.
Return value
Keyed array containing vote choices in descending order and total votes. $choices contains: index = the index of the choice percentage = percentage of votes choice received. votes = the number of votes received.
1 call to advpoll_pooled_vote()
- advpoll_get_votes in includes/
advpoll_voteapi.inc - Get all votes related to a node by content type and node id.
File
- includes/
advpoll_voteapi.inc, line 95
Code
function advpoll_pooled_vote($results) {
$tallied = array();
$total = 0;
foreach ($results as $result) {
if (isset($tallied[$result['tag']])) {
$tallied[$result['tag']]++;
}
else {
$tallied[$result['tag']] = 1;
}
$total++;
}
$tabulated = advpoll_calculate_percentage($tallied, $total);
return array(
'choices' => $tabulated,
'total' => $total,
);
}