/** * Hydrate $object with the provided $data. * * @param array $data * @param \Application\Model\Entity\Match $match * * @return \Application\Model\Entity\Match */ public function hydrate(array $data, $match) { $match->setGames($data['games']); if ($match instanceof DoubleMatch) { $match->setTeamOne($this->repository->find($data['teamOneAttack']), $this->repository->find($data['teamOneDefence'])); $match->setTeamTwo($this->repository->find($data['teamTwoAttack']), $this->repository->find($data['teamTwoDefence'])); } return $match; }
/** * @param \Application\Model\Entity\Match $match * * @return string */ public function __invoke($match) { $gameResults = array(); $games = $match->getGames(); foreach ($games as $game) { $goalsOne = $game->getGoalsTeamOne(); $goalsTwo = $game->getGoalsTeamTwo(); $gameResults[] = $goalsOne . ":" . $goalsTwo; } return implode(", ", $gameResults); }
/** * @param int $goalsTeamOne * @param int $goalsTeamTwo */ protected function addGameToMatch($goalsTeamOne, $goalsTeamTwo) { $game = new Game(); $game->setGoalsTeamOne($goalsTeamOne); $game->setGoalsTeamTwo($goalsTeamTwo); $this->match->addGame($game); }
/** * @param Match $match * * @return bool */ protected function matchHasNewPlayer(Match $match) { foreach ($match->getPlayer() as $player) { if ($player->getMatchCount() < 30) { return true; } } return false; }
/** * @param Match $match * @param PlannedMatch $plannedMatch * * @return ViewModel */ protected function handleForm($match, $plannedMatch = null) { $tournament = $match->getTournament(); $factory = new \Application\Form\Factory($this->playerRepository); $form = $factory->getMatchForm($tournament, $plannedMatch); $form->bind($match); if ($this->request->isPost()) { $form->setData($this->request->getPost()); if ($form->isValid()) { if ($match->isResultValid()) { $tournament->matchPlayed($match, $plannedMatch); $this->matchRepository->persist($match); if ($plannedMatch != null) { $this->plannedMatchRepository->persist($plannedMatch); } $ranking = new Elo(); $log = $ranking->calculateMatch($match); $this->pointLogRepository->persist($log); foreach ($match->getPlayer() as $player) { $this->playerRepository->persist($player); } return $this->redirect()->toRoute('tournament/show', array('id' => $tournament->getId())); } else { $form->setMessages(array('submit' => array('You need to play more matches'))); } } } if ($match->getId() != null) { $url = $this->url()->fromRoute('match/edit/', array('mid' => $match->getId())); $form->setAttribute('action', $url); } $view = new ViewModel(array('form' => $form, 'tournament' => $tournament)); $view->setTemplate('application/match/edit'); if ($this->getRequest()->isXmlHttpRequest()) { $view->setTerminal(true); } return $view; }