You are here

public function RateAverage::calculateResult in Rate 8.2

Calculate results.

Overrides RateVoteResultBase::calculateResult

File

src/Plugin/VoteResultFunction/RateAverage.php, line 22

Class

RateAverage
An average of a set of votes.

Namespace

Drupal\rate\Plugin\VoteResultFunction

Code

public function calculateResult($votes) {
  $total = 0;
  $votes = $this
    ->getVotesForField($votes);
  foreach ($votes as $vote) {
    $total += (int) $vote
      ->getValue();
  }
  if ($total == 0) {
    return 0;
  }
  return $total / count($votes);
}