function advpoll_cancel_ranking in Advanced Poll 6.2
Same name and namespace in other branches
- 5 modes/ranking.inc \advpoll_cancel_ranking()
- 6.3 modes/ranking.inc \advpoll_cancel_ranking()
- 6 modes/ranking.inc \advpoll_cancel_ranking()
Hook to handle a cancelled vote for a ranking poll.
File
- modes/
ranking.inc, line 830 - Handle ranking votes, e.g. choice A is preferred over choice B, which in turn is preferred over choice C.
Code
function advpoll_cancel_ranking($node, $user_vote) {
// Remove choice if this was the last vote for a write-in.
if ($node->writeins) {
$recalculate = FALSE;
foreach ($user_vote as $vote) {
if ($node->choice[$vote['tag']]['writein']) {
// Check if there are any other votes for this write-in.
$count = db_result(db_query('SELECT COUNT(1) FROM {votingapi_vote} WHERE content_id = %d AND tag = %d', $node->nid, $vote['tag']));
if ($count == 0) {
// Delete the write-in because no one else voted for it.
db_query('DELETE FROM {advpoll_choices} WHERE cid = %d', $vote['tag']);
$recalculate = TRUE;
watchdog('content', 'Removed write-in choice %choice after the last vote was cancelled.', array(
'%choice' => $node->choice[$vote['tag']]['label'],
));
}
}
}
if ($recalculate) {
votingapi_recalculate_results('advpoll', $node->nid);
}
}
}