function advpoll_ranking_process_votes in Advanced Poll 7
Same name and namespace in other branches
- 7.3 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_process_votes()
- 7.2 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_process_votes()
1 call to advpoll_ranking_process_votes()
- advpoll_ranking_submit in advpoll_ranking/
advpoll_ranking.module
File
- advpoll_ranking/
advpoll_ranking.module, line 401
Code
function advpoll_ranking_process_votes($data, $nid, $votes) {
if ($data->behavior == 'borda') {
// borda is based upon the number of possible choices.
// algorithm is (number of choices - ranking) where first
// place is 0.
// Ref: http://en.wikipedia.org/wiki/Borda_count#Voting_and_counting
$points = count($data->choices);
}
else {
// runoff voting ranks each user's choices and eliminates
// low score.
// Ref: http://en.wikipedia.org/wiki/Instant-runoff_voting#Election_procedure
$points = $data->max_choices;
}
foreach ($votes as $ranking) {
$vote = array();
$vote['type'] = 'advpoll';
$vote['tag'] = $ranking['id'];
$vote['nid'] = $nid;
$vote['value'] = $points - ($ranking['rank'] - 1);
$vote['mode'] = $data->mode;
$vote['duration'] = $data->cookie_duration;
advpoll_add_votes($vote);
}
}