You are here

function _advpoll_user_voted in Advanced Poll 5

Same name and namespace in other branches
  1. 6.3 advpoll.module \_advpoll_user_voted()
  2. 6 advpoll.module \_advpoll_user_voted()
  3. 6.2 advpoll.module \_advpoll_user_voted()

Check if a user has voted on a poll.

Return value

Array indicating if user voted and, if so, if the vote is cancellable.

4 calls to _advpoll_user_voted()
advpoll_load in ./advpoll.module
Implementation of hook_load().
advpoll_voting_binary_form_validate in modes/binary.inc
Check if the submitted key exists, just to make sure the form is not bypassed.
advpoll_voting_ranking_form_validate in modes/ranking.inc
Implementation of the vote validation hook for the runoff module.
_advpoll_vote_response in ./advpoll.module

File

./advpoll.module, line 838
Advanced Poll - a sophisticated polling module for voting, elections, and group decision-making.

Code

function _advpoll_user_voted($nid) {
  global $user;
  $voted = FALSE;
  $cancel_vote = FALSE;
  if ($user->uid) {

    // Voter is logged in.
    $voted = count(votingapi_get_user_votes('advpoll', $nid)) > 0;
    if ($voted) {
      $cancel_vote = TRUE;
    }
  }
  else {

    // Voter is anonymous.
    // TODO: add options to check cookie rather than IP for anonymous votes.
    // Check if there is already an anonymous vote for this IP.
    $host = $_SERVER['REMOTE_ADDR'] . ($_SERVER['HTTP_X_FORWARDED_FOR'] ? '-' . $_SERVER['HTTP_X_FORWARDED_FOR'] : '');
    $result = db_query("SELECT value FROM {votingapi_vote} WHERE content_id = %d AND content_type = 'advpoll' AND hostname = '%s' AND uid = 0", $nid, $host);
    if (db_num_rows($result) > 0) {
      $voted = TRUE;
      $cancel_vote = TRUE;
    }
  }
  return array(
    $voted,
    $cancel_vote,
  );
}