function advpoll_update_choices in Advanced Poll 7.2
Same name and namespace in other branches
- 7.3 advpoll.module \advpoll_update_choices()
- 7 advpoll.module \advpoll_update_choices()
2 calls to advpoll_update_choices()
- advpoll_display_borda_results in advpoll_ranking/
advpoll_ranking.module - advpoll_display_results in ./
advpoll.module
File
- ./
advpoll.module, line 474
Code
function advpoll_update_choices($choices, $results) {
$choiceSet = array();
foreach ($choices as $choice) {
$choiceSet[$choice['choice_id']] = $choice['choice'];
}
$final = array();
foreach ($results as $result) {
$final[] = array(
'title' => $choiceSet[$result['index']],
'percentage' => $result['percentage'],
'votes' => $result['votes'],
'tag' => $result['index'],
);
// choice has been accounted for - remove it
unset($choiceSet[$result['index']]);
}
// If there are still items in this array, it means they have
// no votes associated with them but they still need to be
// rendered.
if (count($choiceSet) > 0) {
foreach ($choiceSet as $key => $choice) {
$final[] = array(
'title' => $choice,
'percentage' => 0,
'votes' => 0,
'tag' => $key,
);
}
}
return $final;
}