/** * Verify that the form data was not manipulated * * @param Combination $combination * @param VoteCombination $voteCombination * * @return boolean */ private function verifyFormData(Combination $combination, VoteCombination $voteCombination) { // check if the competition matches if ($combination->getCompetition() !== $voteCombination->getCompetition()) { return false; } // check if the combination matches if ($combination !== $voteCombination->getCombination()) { return false; } // check if the voteForPicture is a valid option if (!in_array($voteCombination->getVoteForPicture(), $combination->getPictures())) { return false; } return true; }
/** * Update a combination status * * @param Competition $competition * @param Picture $leftPicture * @param Picture $rightPicture * * @return void */ private function updateCombinationStatus(Competition $competition, Picture $leftPicture, Picture $rightPicture) { if ($leftPicture->getId() < $rightPicture->getId()) { $combination = $this->getCombinationByPictures($competition, $leftPicture, $rightPicture); if (empty($combination)) { $combination = new Combination(); $combination->setCompetition($competition); $combination->setLeftPicture($leftPicture); $combination->setRightPicture($rightPicture); } $active = false; if ($leftPicture->isActive() && $rightPicture->isActive()) { $active = true; } if ($combination->getActive() !== $active) { $combination->setActive($active); $this->entityManager->persist($combination); } } }