You are here

function advpoll_user_eligibility in Advanced Poll 7.2

Same name and namespace in other branches
  1. 7.3 includes/advpoll_voteapi.inc \advpoll_user_eligibility()
  2. 7 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 205

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;
}