You are here

function advpoll_get_votes in Advanced Poll 7.3

Same name and namespace in other branches
  1. 7 includes/advpoll_voteapi.inc \advpoll_get_votes()
  2. 7.2 includes/advpoll_voteapi.inc \advpoll_get_votes()

Get all votes related to a node by content type and node id.

Parameters

$nid: Node ID of an advanced poll.

$data: Data from the node formatted by one of the helper functions in the advpoll_helper.inc document.

Return value

array An array containing the keys:

  • choices: The index of each choice with its tallied votes.
  • total: The total of all votes.
5 calls to advpoll_get_votes()
advpoll_display_borda_results in advpoll_ranking/advpoll_ranking.module
Determines how to theme poll results based on settings in $data.
advpoll_display_results in ./advpoll.module
Determines how to theme poll results.
_advpoll_clear_votes_access in ./advpoll.module
Clear votes access callback.
_advpoll_results_access in ./advpoll.module
Results access callback.
_advpoll_votes_access in ./advpoll.module
Votes access callback.

File

includes/advpoll_voteapi.inc, line 24
Advanced Poll Vote API Include.

Code

function advpoll_get_votes($nid, $data) {
  $criteria = array();
  $criteria['entity_id'] = $nid;
  $criteria['entity_type'] = 'node';
  $tags = array();
  foreach ($data->choices as $choice) {
    $tags[$choice['choice_id']] = $choice['choice_id'];
  }
  $criteria['tag'] = $tags;
  $results = votingapi_select_votes($criteria);
  if ($data->behavior === 'approval') {
    $tabulated = advpoll_approval_vote($results);
  }
  elseif ($data->behavior === 'pool') {
    $tabulated = advpoll_pooled_vote($results);
  }
  else {
    $tabulated = advpoll_default_vote($results);
  }
  return $tabulated;
}