function advpoll_ranking_process_votes in Advanced Poll 7.3
Same name and namespace in other branches
- 7 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_process_votes()
- 7.2 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_process_votes()
Handles voting algorithm used by different types of ranking polls and passes off results to voting API.
Parameters
$nid: Node id of the poll.
$data: Data from the node formatted by one of the helper functions in the advpoll_helper.inc document.
votes: An array of voting information needed by Voting API.
2 calls to advpoll_ranking_process_votes()
- advpoll_draggable_submit in advpoll_ranking/
advpoll_ranking.module - Submit handler for ranking polls.
- advpoll_ranking_submit in advpoll_ranking/
advpoll_ranking.module - Submit handler for ranking polls.
File
- advpoll_ranking/
advpoll_ranking.module, line 488
Code
function advpoll_ranking_process_votes($data, $nid, $votes) {
if ($data->behavior == 'borda' || $data->behavior == 'borda_all' || $data->behavior == 'runoff_all') {
/* Borda is based upon the number of possible choices.
* algorithm is (number of choices - ranking) where first
* place is 0.
* @see 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.
* @see http://en.wikipedia.org/wiki/Instant-runoff_voting#Election_procedure
*/
$points = $data->max_choices;
}
foreach ($votes as $ranking) {
$vote = array();
$vote['type'] = 'node';
$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);
}
}