public function load(\Doctrine\Common\Persistence\ObjectManager $manager) { $faker = \Faker\Factory::create(); for ($j = 1; $j <= self::NUMBER; $j++) { $latLng = LatLngHelper::getRandomLatLngNear(46.30639, 16.339145); $location = new Location(); $location->setPlayer($this->getReference('player' . $j)); $location->setGame($this->getReference('game')); $location->setLat($latLng['lat']); $location->setLng($latLng['lng']); $manager->persist($location); } $manager->flush(); }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var Game $game */ $game = $this->getContainer()->get('doctrine')->getManager()->getRepository('AppBundle:Game')->find(1); if (empty($game)) { return null; } /** @var EntityManager $manager */ $manager = $this->getContainer()->get('doctrine')->getManager(); $getData = function ($player) use($manager, $game) { $manager->refresh($player); /** @var Player $player */ if (!$player->isLive()) { return; } /** @var Location $oldLocation */ $oldLocation = $manager->getRepository('AppBundle:Location')->findOneBy(['player' => $player], ['createdAt' => 'DESC']); if (!empty($oldLocation)) { $latLng = ['lat' => $oldLocation->getLat() + rand(1, 9) / 1000000 * (rand() % 2 == 0 ? 1 : -1), 'lng' => $oldLocation->getLng() + rand(1, 9) / 1000000 * (rand() % 2 == 0 ? 1 : -1)]; } else { $latLng = LatLngHelper::getRandomLatLngNear(46.30639, 16.339145); } $location = new Location(); $location->setPlayer($player); $location->setGame($game); $location->setLat($latLng['lat']); $location->setLng($latLng['lng']); $manager->persist($location); }; while (true) { $stat = array(); /** @var Player $player */ foreach ($game->getTeam1()->getPlayers() as $player) { $stat[] = $getData($player); } /** @var Player $player */ foreach ($game->getTeam2()->getPlayers() as $player) { $stat[] = $getData($player); } $manager->flush(); $output->writeln('Updated'); //sleep(1); } }