function advpoll_default_vote in Advanced Poll 7
Same name and namespace in other branches
- 7.3 includes/advpoll_voteapi.inc \advpoll_default_vote()
- 7.2 includes/advpoll_voteapi.inc \advpoll_default_vote()
Default voting count
Uses the 'value' field returned by the voting API to tally votes and arrive at percentages.
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_default_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 124
Code
function advpoll_default_vote($results) {
$tallied = array();
$total = 0;
$points = 0;
$totalpoints = 0;
foreach ($results as $result) {
$points = (int) $result['value'];
if (isset($tallied[$result['tag']])) {
$tallied[$result['tag']] += $points;
}
else {
$tallied[$result['tag']] = $points;
}
$totalpoints += $points;
$total++;
}
$tabulated = advpoll_calculate_percentage($tallied, $totalpoints);
return array(
'choices' => $tabulated,
'total' => $total,
);
}