You are here

function advpoll_approval_vote in Advanced Poll 7

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

Tally votes by approval method.

For approval voting, multiple choices cast by a single user count as one vote.

Parameters

$results : Results returned from voting api.

Return value

Keyed 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_approval_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 53

Code

function advpoll_approval_vote($results) {
  $tallied = array();
  $source = array();
  $total = 0;
  foreach ($results as $result) {
    if (isset($tallied[$result['tag']])) {
      $tallied[$result['tag']]++;
    }
    else {
      $tallied[$result['tag']] = 1;
    }
    if (!in_array($result['timestamp'], $source)) {
      $source[] = $result['timestamp'];
    }
  }
  $total = count($source);
  $tabulated = advpoll_calculate_percentage($tallied, $total);
  return array(
    'choices' => $tabulated,
    'total' => $total,
  );
}