function advpoll_approval_vote in Advanced Poll 7.3
Same name and namespace in other branches
- 7 includes/advpoll_voteapi.inc \advpoll_approval_vote()
- 7.2 includes/advpoll_voteapi.inc \advpoll_approval_vote()
Tally votes by approval method.
For approval voting, multiple choices cast by a single user count as one vote.
Parameters
array $results: Results returned from voting api.
Return value
array Associative 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_approval_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 67 - Advanced Poll Vote API Include.
Code
function advpoll_approval_vote($results) {
$tallied = array();
$source = array();
foreach ($results as $result) {
if (isset($tallied[$result['tag']])) {
$tallied[$result['tag']]++;
}
else {
$tallied[$result['tag']] = 1;
}
$source[$result['timestamp']] = 1;
}
$total = count($source);
$tabulated = advpoll_calculate_percentage($tallied, $total);
return array(
'choices' => $tabulated,
'total' => $total,
);
}