You are here

function advpoll_user_eligibility in Advanced Poll 7

Same name and namespace in other branches
  1. 7.3 includes/advpoll_voteapi.inc \advpoll_user_eligibility()
  2. 7.2 includes/advpoll_voteapi.inc \advpoll_user_eligibility()
4 calls to advpoll_user_eligibility()
advpoll_cancel_vote_submit in ./advpoll.module
advpoll_node_view in ./advpoll.module
Implements hook_node_view().
advpoll_ranking_cancel_submit in advpoll_ranking/advpoll_ranking.module
advpoll_ranking_node_view in advpoll_ranking/advpoll_ranking.module

File

includes/advpoll_voteapi.inc, line 200

Code

function advpoll_user_eligibility($node) {
  if (!user_access('vote on polls')) {
    return false;
  }
  global $user;
  $data = advpoll_get_data($node);
  if ($data->write_in && !user_access('add write-ins')) {
    return false;
  }
  if ($data->electoral) {
    if (!advpoll_check_electoral_list($user->uid, $node->nid)) {
      return false;
    }
  }
  if ($data->state !== 'open') {
    return false;
  }
  if ($data->start_date > time() || $data->end_date < time()) {
    return false;
  }
  if ($data->mode === 'cookie' && isset($_COOKIE[$node->type . $node->nid])) {
    return false;
  }
  if ($data->mode === 'normal') {
    $criteria = array();
    $criteria['entity_id'] = $node->nid;
    $criteria['entity_type'] = $node->type;
    $criteria['uid'] = $user->uid;
    $results = votingapi_select_votes($criteria);
    if ($results) {
      return false;
    }
  }
  return true;
}