/** * @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; }
public function testTournamentProperty() { $tournament = new League(); $this->match->setTournament($tournament); $this->assertEquals($tournament, $this->match->getTournament()); }