/** * @param Panel $panel */ public function processVotingResult(Panel $panel) { $voting = $panel->getCurrentVoting(); $votesCount = 0; foreach ($voting->getVotingOptions() as $votingOption) { /** @var \Visol\EasyvoteEducation\Domain\Model\VotingOption $votingOption */ $votesCountForVotingOption = $votingOption->getVotes()->count(); $votingOption->setCachedVotes($votesCountForVotingOption); $votesCount = $votesCount + $votesCountForVotingOption; $this->votingOptionRepository->update($votingOption); } $this->persistenceManager->persistAll(); // $votesCount is complete foreach ($voting->getVotingOptions() as $votingOption) { /** @var \Visol\EasyvoteEducation\Domain\Model\VotingOption $votingOption */ if ($votesCount > 0) { $votingResult = round($votingOption->getCachedVotes() / $votesCount, 5) * 100; $votingOption->setCachedVotingResult((int) $votingResult); } else { $votingOption->setCachedVotingResult(0); } $this->votingOptionRepository->update($votingOption); } $this->persistenceManager->persistAll(); }