/**
  * @return array
  */
 public function getGrid()
 {
     $issueGrid = [];
     /** @var Issue $issue */
     foreach ($this->issueRepository->findAll() as $issue) {
         $issueGrid[$issue->getId()]['key'] = $issue->getJiraKey();
         $issueGrid[$issue->getId()]['summary'] = $issue->getSummary();
         /** @var PersistentCollection $votes */
         $votes = $issue->getVotes();
         /** @var Stakeholder $stakeholder */
         foreach ($this->stakeHolderRepository->findAll() as $stakeholder) {
             $vote = $votes->matching(Criteria::create()->where(Criteria::expr()->eq('stakeholder', $stakeholder)))->first();
             $vote = $vote ? $vote->getVote() : 0;
             $issueGrid[$issue->getId()]['stakeholders'][$stakeholder->getId()] = $vote;
         }
     }
     $stakeholderGrid = [];
     foreach ($this->stakeHolderRepository->findAll() as $stakeholder) {
         $stakeholderGrid[$stakeholder->getId()] = ['name' => $stakeholder->getName(), 'allowedVotes' => $stakeholder->getAllowedVotes()];
     }
     return ['stakeholders' => $stakeholderGrid, 'issues' => $issueGrid];
 }
 /**
  * @param Stakeholder $stakeholder
  * @param $votes
  */
 public function hydrateVotes(Stakeholder $stakeholder, $votes)
 {
     if ($stakeholder->getAllowedVotes() !== array_sum($votes)) {
         throw new \RuntimeException('Amount of votes not allowed');
     }
     foreach ($votes as $key => $value) {
         $issue = $this->issueRepository->findOneBy(['jiraKey' => $key]);
         $vote = $this->voteRepository->findOneBy(['issue' => $issue, 'stakeholder' => $stakeholder]);
         if (null === $vote) {
             $vote = new Vote();
             $vote->setIssue($issue);
             $vote->setStakeholder($stakeholder);
         }
         $vote->setVote($value);
         $this->voteRepository->persist($vote);
     }
     $this->voteRepository->flush();
 }