You are here

function advpoll_cancel_binary in Advanced Poll 5

Same name and namespace in other branches
  1. 6.3 modes/binary.inc \advpoll_cancel_binary()
  2. 6 modes/binary.inc \advpoll_cancel_binary()
  3. 6.2 modes/binary.inc \advpoll_cancel_binary()

Hook to handle a cancelled vote for a binary poll.

File

modes/binary.inc, line 310

Code

function advpoll_cancel_binary($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;
        }
      }
    }
    if ($recalculate) {
      votingapi_recalculate_results('advpoll', $node->nid);
    }
  }
}