function advpoll_view_results_binary in Advanced Poll 5
Same name and namespace in other branches
- 6.3 modes/binary.inc \advpoll_view_results_binary()
- 6 modes/binary.inc \advpoll_view_results_binary()
- 6.2 modes/binary.inc \advpoll_view_results_binary()
File
- modes/
binary.inc, line 112
Code
function advpoll_view_results_binary($node, $teaser, $page) {
$content_type = 'advpoll';
$content_id = $node->nid;
$results = votingapi_get_voting_results($content_type, $content_id);
$votes = array();
foreach ($results as $result) {
$vote_value = $result->tag;
if ($vote_value == '_advpoll') {
if ($result->function == 'total_votes') {
$total_votes = $result->value;
}
}
else {
if (isset($node->choice[$vote_value])) {
if (!$votes[$vote_value]) {
$votes[$vote_value] = 0;
}
$votes[$vote_value] = $result->value;
}
}
}
if ($node->choice && $total_votes > 0) {
// Add in any choices that received no votes.
foreach ($node->choice as $i => $choice) {
if (!isset($votes[$i])) {
$votes[$i] = 0;
}
}
// Sort results by votes, descending.
arsort($votes);
// Display results for each possible choice
foreach ($votes as $i => $count) {
$choice = $node->choice[$i];
$percentage = round(100 * $votes[$i] / $total_votes, 0);
$output .= theme('advpoll_bar', _advpoll_choice_markup($choice['label'], $node->format, FALSE), $percentage, format_plural($count, '1 vote', '@count votes'), $choice);
}
}
return array(
'results' => $output,
'votes' => $total_votes,
);
}