/**
  * Transforms a string to an object.
  *
  * @param  string $locationText
  * @return Location
  */
 public function reverseTransform($locationText)
 {
     $location = $this->em->getRepository('AppBundle:Location')->findOneByTitle($locationText);
     if (null === $location) {
         $location = new Location();
         $location->setTitle($locationText);
     }
     return $location;
 }
Example #2
0
 public function createLocation(User $user, $ifnotexists = false)
 {
     if ($ifnotexists === false || $this->anyLocationExists($user) === false) {
         $loc = new Location($user);
         if ($loc !== null) {
             $generator = new SecureRandom();
             $loc->setPassword(bin2hex($generator->nextBytes(2)));
             $loc->setCaption($this->translator->trans('Location') . " #" . ($this->totalCount($user) + 1));
             return $loc;
         }
     }
     return null;
 }
 /**
  * 
  */
 public function putLocationsAction(Location $location, Request $request)
 {
     $id = $location->getId();
     echo $id;
     die;
     $location = new Location();
     $location->setId($id);
     $errors = $this->treatAndValidateRequest($location, $request);
     if (count($errors) > 0) {
         return new View($errors, Response::HTTP_UNPROCESSABLE_ENTITY);
     }
     $this->persistAndFlush($location);
     return '';
 }
 public function testLocationFormFailure()
 {
     $formData = array('lokaalNummer' => '9999');
     $form = $this->factory->create(LocationType::class);
     // submit the data to the form directly
     $form->submit($formData);
     $location = new Location();
     $location->setLokaalNummer("8888");
     $this->assertTrue($form->isSynchronized());
     $this->assertNotEquals($location, $form->getData());
     $view = $form->createView();
     $children = $view->children;
     foreach (array_keys($formData) as $key) {
         $this->assertArrayHasKey($key, $children);
     }
 }
 private function buildLocEntity($region, $regionName, $parent, $em)
 {
     $entity = new Location();
     $regionName = $regionName ?: $region->getDescription();
     $entity->setDescription($regionName);
     $entity->setCreatedBy($em->getRepository('AppBundle:User')->findOneBy(array('id' => '6')));
     $entity->setLocationType($em->getRepository('AppBundle:LocationType')->findOneBy(array('id' => 1)));
     $childLocs = $region->getLocations();
     foreach ($childLocs as $loc) {
         $entity->addChildLocs($loc);
     }
     if ($parent !== null) {
         $entity->setParentLoc($parent);
     }
     $em->persist($entity);
     $em->flush();
 }
 private function BuildLocEntity($country, $cntryName, $em)
 {
     $entity = new Location();
     $entity->setDescription($cntryName);
     $entity->setCreatedBy($em->getRepository('AppBundle:User')->findOneBy(array('id' => '6')));
     //Sarah
     $entity->setLocationType($em->getRepository('AppBundle:LocationType')->findOneBy(array('id' => 2)));
     $parentDesc = $country->getRegion()->getDescription();
     $parent = $em->getRepository('AppBundle:Location')->findOneBy(array('description' => $parentDesc));
     $entity->setParentLoc($parent);
     $childLocs = $country->getLocations();
     foreach ($childLocs as $loc) {
         $entity->addChildLocs($loc);
     }
     $em->persist($entity);
     $em->flush();
 }
 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);
     }
 }
Example #10
0
 /**
  * Add childLoc.
  *
  * @param \AppBundle\Entity\Location $childLoc
  *
  * @return Location
  */
 public function addChildLocs(\AppBundle\Entity\Location $childLoc)
 {
     $this->childLocs[] = $childLoc;
     $childLoc->setParentLoc($this);
     return $this;
 }
 private function createDeleteDoctorForm(Location $location)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('deleteDoctorFromLocation', array('id' => $location->getId())))->setMethod('DELETE')->getForm();
 }