/** * @return array|\Zend\Http\Response */ public function editTournamentAction() { $id = $this->params()->fromRoute('id'); $tournament = $this->tournamentRepository->find($id); $lock = count($this->matchRepository->findForTournament($tournament)) > 0; $form = $lock ? new TournamentForm(true) : new TournamentForm(); if (!$tournament instanceof \Application\Model\Entity\Tournament) { throw new \RuntimeException('Invalid tournament ID'); } $form->bind($tournament); if ($lock) { $form->setInputFilter(new \Application\Form\InputFilter\Tournament($this->tournamentRepository, true)); } else { $form->setInputFilter(new \Application\Form\InputFilter\Tournament($this->tournamentRepository)); } if ($this->request->isPost()) { $form->setData($this->request->getPost()); if ($form->isValid()) { $this->tournamentRepository->persist($tournament); return $this->redirect()->toRoute('tournaments'); } } return array('form' => $form); }