You are here

public function CountUp::calculateResult in Rate 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/VoteResultFunction/CountUp.php \Drupal\rate\Plugin\VoteResultFunction\CountUp::calculateResult()

Performs the calculations on a set of votes to derive the result.

Parameters

\Drupal\votingapi\Entity\Vote[] $votes: An array of Vote entities.

Return value

int A result based on the supplied votes.

Overrides VoteResultFunctionInterface::calculateResult

File

src/Plugin/VoteResultFunction/CountUp.php, line 21

Class

CountUp
The total number of positive votes.

Namespace

Drupal\rate\Plugin\VoteResultFunction

Code

public function calculateResult($votes) {
  $up = 0;
  foreach ($votes as $vote) {
    if ($vote
      ->getValue() > 0) {
      $up++;
    }
  }
  return $up;
}