public function FieldAverage::calculateResult in Votingapi Widgets 8
Calculate results.
Overrides FieldVoteResultBase::calculateResult
File
- src/
Plugin/ VoteResultFunction/ FieldAverage.php, line 22
Class
- FieldAverage
- A sum of a set of votes.
Namespace
Drupal\votingapi_widgets\Plugin\VoteResultFunctionCode
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);
}