You are here

function advpoll_default_vote in Advanced Poll 7.3

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

Default voting count.

Uses the 'value' field returned by the voting API to tally votes and arrive at percentages.

Parameters

array $results: Results returned from voting api.

Return value

array Associative array containing vote choices in descending order and total votes. $choices contains:

  • index: The index of the choice.
  • percentage: Percentage of votes choice received.
  • votes: The number of votes received.
1 call to advpoll_default_vote()
advpoll_get_votes in includes/advpoll_voteapi.inc
Get all votes related to a node by content type and node id.

File

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

Code

function advpoll_default_vote($results) {
  $tallied = array();
  $total = 0;
  $total_points = 0;
  foreach ($results as $result) {
    $points = (int) $result['value'];
    if (isset($tallied[$result['tag']])) {
      $tallied[$result['tag']] += $points;
    }
    else {
      $tallied[$result['tag']] = $points;
    }
    $total_points += $points;
    $total++;
  }
  $tabulated = advpoll_calculate_percentage($tallied, $total_points);
  return array(
    'choices' => $tabulated,
    'total' => $total,
  );
}