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();
 }
 /**
  *
  * @Route("/locations", name="api.post.location")
  * @Method("POST")
  */
 public function postLocationAction(Request $request)
 {
     $data = $this->getDataFromRequest($request);
     $player = $this->getDoctrine()->getManager()->getRepository('AppBundle:Player')->findOneBy(['user' => $this->getUser()]);
     $location = new Location();
     $location->setLat($data['lat']);
     $location->setLng($data['lng']);
     $game = $this->getDoctrine()->getManager()->getRepository('AppBundle:Game')->findOneBy(['id' => @$data['game']]);
     if (!empty($game)) {
         $location->setGame($game);
     }
     $location->setPlayer($player);
     $this->getDoctrine()->getManager()->persist($location);
     $this->getDoctrine()->getManager()->flush();
     return $this->createResponse([self::KEY_STATUS => self::STATUS_OK, self::KEY_MESSAGE => 'Location submitted']);
 }
 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);
     }
 }