private function addMissingParentRegions($em)
 {
     $entity = new Region();
     $entity->setDescription("Asia");
     $em->persist($entity);
     $em->flush();
 }
Esempio n. 2
0
 /**
  * @Route("/get-tournaments/{id}", name="get-tournaments")
  */
 public function getTournamentAction(Region $region)
 {
     $tournaments = $region->getTournaments();
     $ret = array();
     foreach ($tournaments as $tournament) {
         $ret[] = array('id' => $tournament->getId(), 'name' => $tournament->getName());
     }
     $content = array('tournaments' => $ret);
     return new JsonResponse($content);
 }
Esempio n. 3
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 getRegionTeams(Region $region)
 {
     $teams = $this->whoscored->loadStatistics('regionteams', array('id' => $region->getWsId()));
     foreach ($teams as $team) {
         if ($this->em->getRepository('AppBundle:Team')->findOneByWsId($team[0]) !== null) {
             continue;
         }
         $ret = new Team();
         $ret->setWsId($team[0]);
         $ret->setName($team[1]);
         $this->em->persist($ret);
         unset($ret);
     }
     $this->em->flush();
 }
Esempio n. 5
0
 function parseCSVAction($from, $to)
 {
     die('nope');
     $em = $this->getDoctrine()->getManager();
     $file = __DIR__ . '/../../../_Njemacka.csv';
     //		$file = __DIR__ . '/../../../regions_subregions.csv';
     //		$file = __DIR__ . '/../../../regions_subregions_city2.csv';
     $csv = array_map('str_getcsv', file($file));
     //		$csv = str_getcsv(file_get_contents(__DIR__ . '/../../../regions_subregions_city.csv'));
     $country = $em->getRepository('AppBundle:Country')->findOneByEn('Germany');
     if ($country) {
         try {
             $i = 0;
             $count = 0;
             foreach ($csv as $c) {
                 if ($c[0] != 'GRAD' && ($i >= $from && $i <= $to)) {
                     $regionCSV = $c[1];
                     $region = $em->getRepository('AppBundle:Region')->findOneByEn($regionCSV);
                     if (!$region) {
                         $region = new Region();
                         $region->setCountry($country);
                         $region->setEn($c[1]);
                         //                            $region->setDe($c[2]);
                         # Depends on country
                         //                            $region->setIt($c[2]);
                         $em->persist($region);
                         $em->flush();
                     }
                     $subregion = false;
                     //                        $subregionCSV = $c[1];
                     //                        $subregion = $em->getRepository('AppBundle:Subregion')->findOneByEn($subregionCSV);
                     //                        if (!$subregion) {
                     //                            $subregion = new Subregion();
                     //                            $subregion->setRegion($region);
                     //                            $subregion->setEn($c[1]);
                     //                            $em->persist($subregion);
                     //                            $em->flush();
                     //                        }
                     $cityCSV = $c[0];
                     $city = $em->getRepository('AppBundle:City')->findOneByEn($cityCSV);
                     if (!$city) {
                         $city = new City();
                         $city->setRegion($region);
                         $city->setEn($cityCSV);
                         if ($subregion) {
                             $city->setSubregion($subregion);
                         }
                         $em->persist($city);
                         $em->flush();
                     }
                     $count++;
                 }
                 $i++;
             }
         } catch (\Exception $e) {
             return new Response($e);
         }
     }
     return new Response($count);
     //		echo'<pre>';print_r($csv);echo'</pre>';
 }
Esempio n. 6
0
 /**
  * @Route("/region/create", name="region_create")
  */
 public function createRegionAction()
 {
     $country = $this->getDoctrine()->getRepository('AppBundle:Country')->findOneByName("Ukraine");
     $region = new Region();
     $region->setName('Kiev area');
     $region->setCountry($country);
     $em = $this->getDoctrine()->getManager();
     $em->persist($country);
     $em->persist($region);
     $em->flush();
     return new Response('Created region id ' . $region->getId());
 }
Esempio n. 7
0
 /**
  * Get cities by Region
  * @param Region $region
  * @return Response
  */
 public function citiesRegionAction(Region $region)
 {
     $em = $this->getDoctrine()->getManager();
     $cities = $em->getRepository('AppBundle:City')->getByRegion($region->getId());
     return $this->render('AdminBundle:Location/City:list.html.twig', array('cities' => $cities));
 }
 /**
  * @param OutputInterface $output
  */
 private function getLocations(OutputInterface $output)
 {
     $output->writeln('<info>Starting to get Locations</info>');
     $output->writeln('<info>URL: ' . $this->url . 'Locations+Overview</info>');
     $html = file_get_contents($this->url . 'Locations+Overview');
     $crawler = new Crawler($html);
     /* Get Regions by Faction */
     $factionRegions = $crawler->filter('.span_1_of_4');
     foreach ($factionRegions as $domElement) {
         /* @var \DOMElement $domElement */
         $content = trim($domElement->textContent);
         $locations = array_map('trim', explode("\n", $content));
         $output->writeln('<info>Getting Factions</info>');
         $faction = $this->em->getRepository('AppBundle:Faction')->findOneBy(array('name' => $locations[0]));
         $output->writeln('<info>Faction: ' . $locations[0] . '</info>');
         if (!$faction instanceof Faction) {
             $faction = new Faction();
             $faction->setName($locations[0]);
             $this->em->persist($faction);
         }
         unset($locations[0]);
         $output->writeln('<info>Getting Regions</info>');
         foreach ($locations as $r) {
             $output->writeln('<info>Region: ' . $r . '</info>');
             $region = $this->em->getRepository('AppBundle:Region')->findOneBy(array('name' => $r));
             if (!$region instanceof Region) {
                 $region = new Region();
                 $region->setName($r);
                 $region->setFaction($faction);
                 $this->em->persist($region);
             }
         }
     }
     $this->em->flush();
     /* Get Region by Province */
     $provinceRegions = $crawler->filter('table.wiki_table');
     $output->writeln('<info>Getting provinces</info>');
     $provincesArray = array();
     foreach ($provinceRegions->children() as $domElement) {
         $output->writeln('<info>Making a Province Array</info>');
         /* @var \DOMElement $domElement */
         $content = trim($domElement->textContent);
         $contentArray = array_map('trim', explode("\n", $content));
         $index = $contentArray[0];
         unset($contentArray[0]);
         if ($index != 'Province') {
             $provincesArray[$index] = array_map('trim', explode(',', $contentArray[1]));
         }
     }
     $output->writeln('<info>Saving Factions</info>');
     foreach ($provincesArray as $prov => $regions) {
         $output->writeln('<info>' . $prov . '</info>');
         $province = $this->em->getRepository('AppBundle:Province')->findOneBy(array('name' => $prov));
         if (!$province instanceof Province) {
             $province = new Province();
             $province->setName($prov);
             $this->em->persist($province);
         }
         foreach ($regions as $r) {
             $output->writeln('<info>' . $r . '</info>');
             $region = $this->em->getRepository('AppBundle:Region')->findOneBy(array('name' => $r));
             if (!$region instanceof Region) {
                 $region = new Region();
                 $region->setName($r);
             }
             $region->setProvince($province);
             $this->em->persist($region);
         }
     }
     $this->em->flush();
     $output->writeln('<info>We\'re done.</info>');
 }
Esempio n. 9
0
 /**
  * Creates a form to delete a Region entity.
  *
  * @param Region $region The Region entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Region $region)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('region_delete', array('id' => $region->getId())))->setMethod('DELETE')->getForm();
 }