/** * Add new tournament to a host * @Route("/edit/tournament/add/{hostid}", name="_edit_tournament_add") * @Template("ICupPublicSiteBundle:Edit:edittournament.html.twig") */ public function addTournamentAction($hostid, Request $request) { /* @var $utilService Util */ $utilService = $this->get('util'); $returnUrl = $utilService->getReferer(); /* @var $user User */ $user = $utilService->getCurrentUser(); $host = $this->get('entity')->getHostById($hostid); $utilService->validateEditorAdminUser($user, $host); $tournament = new Tournament(); $tournament->setHost($host); $form = $this->makeTournamentForm($tournament, 'add'); $form->handleRequest($request); if ($form->get('cancel')->isClicked()) { return $this->redirect($returnUrl); } if ($this->checkForm($form, $tournament)) { if ($this->get('logic')->getTournamentByKey($tournament->getKey())) { $form->addError(new FormError($this->get('translator')->trans('FORM.TOURNAMENT.KEYEXIST', array(), 'admin'))); } else { $em = $this->getDoctrine()->getManager(); $em->persist($tournament); $em->flush(); return $this->redirect($returnUrl); } } return array('form' => $form->createView(), 'action' => 'add', 'tournament' => $tournament); }
public function makeTournament() { $host = new Host(); $host->setName("Test host"); // $host->setHostplan(new HostPlan()); $tournament = new Tournament(); $tournament->setName("Test tournament"); $tournament->setDescription("Test edition of a tournament"); $tournament->setEdition("2015"); $tournament->setKey("TST2015"); $tournament->setHost($host); $host->getTournaments()->add($tournament); $editor = new User(); $editor->setUsername("test"); $editor->setName("Test user"); $editor->setPassword(""); $editor->setEmail("*****@*****.**"); $editor->addRole(User::ROLE_EDITOR_ADMIN); $editor->setEnabled(true); $editor->setHost($host); $host->getUsers()->add($editor); $this->em->persist($host); $this->em->flush(); return $tournament; }
/** * Copy objects from another tournament * @Route("/edit/tournament/import/{hostid}", name="_edit_import_tournament") * @Template("ICupPublicSiteBundle:Edit:importtournament.html.twig") */ public function importAction($hostid, Request $request) { /* @var $utilService Util */ $utilService = $this->get('util'); $returnUrl = $utilService->getReferer(); /* @var $user User */ $user = $utilService->getCurrentUser(); $host = $this->get('entity')->getHostById($hostid); $utilService->validateEditorAdminUser($user, $host); $tournament = new Tournament(); $tournament->setHost($host); $form = $this->makeImportForm($tournament); $form->handleRequest($request); if ($form->get('cancel')->isClicked()) { return $this->redirect($returnUrl); } if ($form->isValid()) { $formData = $form->getData(); $tid = $formData['tournament']; if ($tid > 0) { $source_tournament = $this->get('entity')->getTournamentById($tid); if ($source_tournament->getHost()->getId() != $tournament->getHost()->getId()) { throw new ValidationException("NOTTHESAMETOURNAMENT", "Not allowed to import from different host, source=" . $source_tournament->getHost()->getId() . ", target=" . $tournament->getHost()->getId()); } $this->importTournament($source_tournament, $tournament); return $this->redirect($returnUrl); } else { } } return array('form' => $form->createView()); }