Пример #1
0
 public function getPolygon()
 {
     $filename = $this->file;
     if (!file_exists($filename)) {
         throw new \InvalidArgumentException("{$filename} does not exist");
     }
     if ($this->getRegion() == null) {
         throw new \InvalidArgumentException("region must be defined");
     }
     if ($this->getWhathoodUser() == null) {
         throw new \InvalidArguementException("user must be defined");
     }
     $jsonStr = file_get_contents($filename);
     $whathoodUser = $this->getWhathoodUser();
     $json = \Zend\Json\Json::decode($jsonStr);
     $neighborhoods = array();
     $counter = 1;
     foreach ($json->kml->Document->Folder->Placemark as $n) {
         $name = $n->ExtendedData->SchemaData->SimpleData[2]->{'#text'};
         $coordinateString = $n->Polygon->outerBoundaryIs->LinearRing->coordinates;
         $array = explode(' ', $coordinateString);
         $neighborhood = new Neighborhood();
         $neighborhood->setName($name);
         $neighborhood->setRegion($this->getRegion());
         $points = array();
         foreach ($array as $point) {
             list($lng, $lat) = explode(",", $point);
             $points[] = new Point($lng, $lat);
         }
         $lineString = new LineString($points);
         $lineString->close();
         $polygon = new Polygon(array($lineString));
         $neighborhoodPolygon = new UserPolygon();
         $neighborhoodPolygon->setWhathoodUser($whathoodUser);
         $neighborhoodPolygon->setAuthority($this->isAuthority());
         $neighborhoodPolygon->setNeighborhood($neighborhood);
         $neighborhoodPolygon->setPolygon($polygon);
         $neighborhoodPolygon->setRegion($this->getRegion());
         $neighborhoods[] = $neighborhoodPolygon;
     }
     return $neighborhoods;
 }
Пример #2
0
 public function save(UserPolygon &$userPolygon, $flush = true)
 {
     /*
      * REGION
      *
      * does the region already exist, if not we need to save it in all entities
      * because it will get saved multiple times
      */
     try {
         $regionName = $userPolygon->getRegion()->getName();
         $region = $this->regionMapper()->getRegionByName($regionName);
         $userPolygon->setRegion($region);
         $userPolygon->getNeighborhood()->setRegion($region);
     } catch (\Doctrine\ORM\NoResultException $e) {
         $region = $userPolygon->getRegion();
         $this->regionMapper()->save($region);
         $userPolygon->setRegion($region);
         $userPolygon->getNeighborhood()->setRegion($region);
     }
     /*
      * NEIGHBORHOOD
      *
      * does the neighborhood already exist, if it does reset it in the neighborhood
      */
     try {
         $neighborhoodName = $userPolygon->getNeighborhood()->getName();
         $regionName = $userPolygon->getNeighborhood()->getRegion()->getName();
         $neighborhood = $this->neighborhoodMapper()->getNeighborhoodByName($neighborhoodName, $regionName);
         $userPolygon->setNeighborhood($neighborhood);
     } catch (\Doctrine\ORM\NoResultException $e) {
         $this->neighborhoodMapper->save($userPolygon->getNeighborhood());
     }
     $whathoodUser = $this->getMaybeSaveByName($userPolygon->getWhathoodUser()->getIpAddress());
     $userPolygon->setWhathoodUser($whathoodUser);
     if ($userPolygon->getDateTimeAdded() == null) {
         $userPolygon->setDateTimeAdded($this->getCurrentDateTimeAsString());
     }
     $this->em->persist($userPolygon);
     if ($flush) {
         $this->em->flush($userPolygon);
     }
 }
Пример #3
0
 public function save(UserPolygon $userPolygon)
 {
     /*
      * REGION
      *
      * does the region already exist, if not we need to save it in all entities
      * because it will get saved multiple times
      */
     try {
         $regionName = $userPolygon->getRegion()->getName();
         $region = $this->regionMapper()->getRegionByName($regionName);
         $userPolygon->setRegion($region);
         $userPolygon->getNeighborhood()->setRegion($region);
     } catch (\Doctrine\ORM\NoResultException $e) {
         $region = $userPolygon->getRegion();
         $this->regionMapper()->save($region);
         $userPolygon->setRegion($region);
         $userPolygon->getNeighborhood()->setRegion($region);
     }
     $this->logger()->info("after region");
     /*
      * NEIGHBORHOOD
      *
      * does the neighborhood already exist, if it does reset it in the neighborhood
      */
     try {
         $neighborhoodName = $userPolygon->getNeighborhood()->getName();
         $regionName = $userPolygon->getNeighborhood()->getRegion()->getName();
         $neighborhood = $this->neighborhoodMapper()->getNeighborhoodByName($neighborhoodName, $regionName);
         $userPolygon->setNeighborhood($neighborhood);
     } catch (\Doctrine\ORM\NoResultException $e) {
         $this->neighborhoodMapper->save($userPolygon->getNeighborhood());
     }
     $this->logger()->info('after neighborhood');
     $whathoodUser = $this->getMaybeSaveByName($userPolygon->getWhathoodUser()->getIpAddress());
     $userPolygon->setWhathoodUser($whathoodUser);
     if ($userPolygon->getDateTimeAdded() == null) {
         $userPolygon->setDateTimeAdded($this->getCurrentDateTimeAsString());
     }
     if (0) {
         \Zend\Debug\Debug::dump($userPolygon->getId(), 'in UserPolygonMapper');
         exit;
     }
     $this->logger()->info("about to save");
     $this->em->persist($userPolygon);
     $this->logger()->info("about to flush");
     $this->em->flush($userPolygon);
     $this->logger()->info("saved");
 }