function advpoll_add_votes in Advanced Poll 7
Same name and namespace in other branches
- 7.3 includes/advpoll_voteapi.inc \advpoll_add_votes()
- 7.2 includes/advpoll_voteapi.inc \advpoll_add_votes()
Add votes for a given poll.
Parameters
$vote: A keyed array that is used to determine the method in which the vote will be tracked and what values will be passed to votingapi $vote['type'] The content type - either advpoll or advpoll_ranking $vote['tag'] = Tag corresponds to the index of the selected choice $vote['nid'] = The node ID of poll being voted on $vote['mode'] = normal, cookie, or unlimited $vote['duration'] = duration is minutes that the cookie will last if one is set.
2 calls to advpoll_add_votes()
- advpoll_form_submit in ./advpoll.module 
- Submit handler for voting
- advpoll_ranking_process_votes in advpoll_ranking/advpoll_ranking.module 
File
- includes/advpoll_voteapi.inc, line 282 
Code
function advpoll_add_votes($vote) {
  // normal voting uses the voteapi to record user id or ip based on authentication
  if ($vote['mode'] === 'normal') {
    $votes = array(
      'entity_type' => $vote['type'],
      'entity_id' => $vote['nid'],
      'value' => $vote['value'],
      'tag' => $vote['tag'],
    );
  }
  else {
    // unlimited and cookie voting simply add values to the votingapi and bypass
    // user id and ip as source. Ttime stamp instead of ip will prevent a unique
    // id from being tied to these voters.
    if ($vote['mode'] === 'cookie') {
      // necessary to pass Drupal's $cookie_domain to get this to stick.
      // Raw cookies are safe in this case as we're only passing a static value
      // to mark that this user voted on their machine.
      setrawcookie($vote['type'] . $vote['nid'], 'vote', time() + 60 * $vote['duration'], '/', $cookie_domain);
    }
    $votes = array(
      'entity_type' => $vote['type'],
      'entity_id' => $vote['nid'],
      'value' => $vote['value'],
      'tag' => $vote['tag'],
      'uid' => '',
      'vote_source' => time(),
    );
  }
  votingapi_set_votes($votes, $criteria = NULL);
}