Beispiel #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $file = $input->getArgument('file');
     $regions = json_decode(file_get_contents($file));
     foreach ($regions as $region) {
         $reg = new Region();
         $reg->setName($region->name);
         $reg->setWsId($region->id);
         $reg->setType($region->type);
         foreach ($region->tournaments as $tournament) {
             $tour = new Tournament();
             $tour->setRegion($reg);
             $tour->setWsId($tournament->id);
             $tour->setName($tournament->name);
             $em->persist($tour);
         }
         $em->persist($reg);
     }
     $em->flush();
     $io->success('Added regions and tournaments.');
 }
 public function getRegions()
 {
     $regions = json_decode(file_get_contents(__DIR__ . "/../Resources/regions.json"));
     foreach ($regions as $region) {
         $reg = new Region();
         $reg->setName($region->name);
         $reg->setWsId($region->id);
         $reg->setType($region->type);
         foreach ($region->tournaments as $tournament) {
             $tour = new Tournament();
             $tour->setRegion($reg);
             $tour->setWsId($tournament->id);
             $tour->setName($tournament->name);
             $this->em->persist($tour);
         }
         $this->em->persist($reg);
     }
     $this->em->flush();
 }