You are here

function _advpoll_user_voted in Advanced Poll 6.2

Same name and namespace in other branches
  1. 5 advpoll.module \_advpoll_user_voted()
  2. 6.3 advpoll.module \_advpoll_user_voted()
  3. 6 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 878
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_select_votes(array(
      'uid' => $user->uid,
      'content_id' => $nid,
    )));
    if ($voted) {
      $cancel_vote = TRUE;
    }
  }
  else {

    // Voter is anonymous.
    $voted = count(votingapi_select_votes(array(
      'vote_source' => ip_address(),
      'content_id' => $nid,
      'uid' => 0,
    )));
    if ($voted) {

      // Found a vote in the database.
      $cancel_vote = TRUE;
    }
  }
  return array(
    $voted,
    $cancel_vote,
  );
}