/**
  * Add new playground to a site
  * @Route("/edit/playground/add/{siteid}", name="_edit_playground_add")
  * @Template("ICupPublicSiteBundle:Edit:editplayground.html.twig")
  */
 public function addPlaygroundAction($siteid, Request $request)
 {
     /* @var $utilService Util */
     $utilService = $this->get('util');
     $returnUrl = $utilService->getReferer();
     /* @var $user User */
     $user = $utilService->getCurrentUser();
     /* @var $site Site */
     $site = $this->get('entity')->getSiteById($siteid);
     /* @var $tournament Tournament */
     $tournament = $site->getTournament();
     $host = $tournament->getHost();
     $utilService->validateEditorAdminUser($user, $host);
     $playground = new Playground();
     $playground->setSite($site);
     $form = $this->makePlaygroundForm($playground, 'add');
     $form->handleRequest($request);
     if ($form->get('cancel')->isClicked()) {
         return $this->redirect($returnUrl);
     }
     if ($this->checkForm($form, $playground)) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($playground);
         $em->flush();
         return $this->redirect($returnUrl);
     }
     return array('form' => $form->createView(), 'action' => 'add', 'playground' => $playground, 'error' => null);
 }
 public function makePlaygrounds(Tournament $tournament)
 {
     for ($s = 1; $s <= 2; $s++) {
         $site = new Site();
         $site->setName("Test site " . $s);
         $site->setTournament($tournament);
         for ($n = 1; $n <= 2; $n++) {
             $playground = new Playground();
             $playground->setName("Test playground " . $s . "-" . $n);
             $playground->setLocation("");
             $playground->setNo($n);
             $playground->setSite($site);
             $site->getPlaygrounds()->add($playground);
         }
         $tournament->getSites()->add($site);
         $this->em->persist($site);
     }
     $timeslot = new Timeslot();
     $timeslot->setName("Period AM");
     $timeslot->setTournament($tournament);
     $timeslot->setCapacity(2);
     $timeslot->setPenalty(true);
     $timeslot->setRestperiod(60);
     $tournament->getTimeslots()->add($timeslot);
     $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "5-7-2015 9.00"), date_create_from_format("j-n-Y G.i", "5-7-2015 12.00"), false);
     $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "6-7-2015 9.00"), date_create_from_format("j-n-Y G.i", "6-7-2015 12.00"), false);
     $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "7-7-2015 9.00"), date_create_from_format("j-n-Y G.i", "7-7-2015 12.00"), false);
     $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "8-7-2015 9.00"), date_create_from_format("j-n-Y G.i", "8-7-2015 12.00"), true);
     $this->em->persist($timeslot);
     $timeslot = new Timeslot();
     $timeslot->setName("Period PM");
     $timeslot->setTournament($tournament);
     $timeslot->setCapacity(1);
     $timeslot->setPenalty(false);
     $timeslot->setRestperiod(60);
     $tournament->getTimeslots()->add($timeslot);
     $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "5-7-2015 13.00"), date_create_from_format("j-n-Y G.i", "5-7-2015 19.00"), false);
     $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "6-7-2015 13.00"), date_create_from_format("j-n-Y G.i", "6-7-2015 19.00"), false);
     $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "7-7-2015 13.00"), date_create_from_format("j-n-Y G.i", "7-7-2015 19.00"), false);
     $this->addSchedules($tournament, $timeslot, date_create_from_format("j-n-Y G.i", "8-7-2015 13.00"), date_create_from_format("j-n-Y G.i", "8-7-2015 22.00"), true);
     $this->em->persist($timeslot);
     $this->em->flush();
 }
 private function importSites(Tournament $source_tournament, Tournament $tournament)
 {
     $em = $this->getDoctrine()->getManager();
     $tsconversion = $this->importTimeslots($source_tournament, $tournament);
     $cconversion = $this->importCategories($source_tournament, $tournament);
     /* @var $site Site */
     foreach ($source_tournament->getSites() as $site) {
         $new_site = new Site();
         $new_site->setTournament($tournament);
         $new_site->setName($site->getName());
         $em->persist($new_site);
         $em->flush();
         foreach ($site->getPlaygrounds() as $playground) {
             $new_playground = new Playground();
             $new_playground->setSite($new_site);
             $new_playground->setName($playground->getName());
             $new_playground->setNo($playground->getNo());
             $new_playground->setLocation($playground->getLocation());
             $em->persist($new_playground);
             $em->flush();
             $this->importPAttrs($playground, $new_playground, $tsconversion, $cconversion);
         }
     }
 }