function advpoll_add_votes in Advanced Poll 7.3
Same name and namespace in other branches
- 7 includes/advpoll_voteapi.inc \advpoll_add_votes()
- 7.2 includes/advpoll_voteapi.inc \advpoll_add_votes()
Add votes for a given poll.
Parameters
array $vote: An associative array that is used to determine the method in which the vote will be tracked and what values will be passed to votingapi. It contains:
- type: The content type - either advpoll or advpoll_ranking.
- tag: Tag corresponds to the index of the selected choice.
- nid: The node ID of poll being voted on.
- mode: normal, cookie, or unlimited.
- 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 - Handles voting algorithm used by different types of ranking polls and passes off results to voting API.
File
- includes/
advpoll_voteapi.inc, line 318 - Advanced Poll Vote API Include.
Code
function advpoll_add_votes($vote) {
/* Normal voting uses the votingapi 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. Time 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.
*/
global $cookie_domain;
//Check if duration is 0 (IE Session) and set duration based on this.
if ($vote['duration'] == 0) {
$duration = 0;
}
else {
$duration = time() + 60 * $vote['duration'];
}
setrawcookie($vote['nodetype'] . $vote['nid'], '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);
}