function advpoll_user_eligibility in Advanced Poll 7.3
Same name and namespace in other branches
- 7 includes/advpoll_voteapi.inc \advpoll_user_eligibility()
- 7.2 includes/advpoll_voteapi.inc \advpoll_user_eligibility()
Checks for user's eligibility to vote on a given poll.
Provides a series of fall-through tests to determine user's ability to vote.
Parameters
$node: The poll node.
Return value
bool TRUE or FALSE.
4 calls to advpoll_user_eligibility()
- advpoll_cancel_vote_submit in ./
advpoll.module - Submit function for cancelling a vote.
- advpoll_node_view in ./
advpoll.module - Implements hook_node_view().
- advpoll_ranking_cancel_vote_submit in advpoll_ranking/
advpoll_ranking.module - Submit function for cancelling a vote.
- advpoll_ranking_node_view in advpoll_ranking/
advpoll_ranking.module - Implements hook_node_view().
File
- includes/
advpoll_voteapi.inc, line 222 - Advanced Poll Vote API Include.
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;
}
// It is possible for a user to not set a start or end date.
if ($data->start_date && $data->end_date) {
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';
$criteria['value_type'] = 'percent';
$criteria['uid'] = $user->uid;
if (!$user->uid) {
$criteria['vote_source'] = ip_address();
}
$results = votingapi_select_votes($criteria);
if ($results) {
return FALSE;
}
}
$access = TRUE;
$context = array(
'node' => $node,
'data' => $data,
);
drupal_alter('advpoll_user_eligibility_post', $access, $context);
return $access;
}