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; }
public function setRegion($data) { $this->__load(); return parent::setRegion($data); }
public function save(NeighborhoodEntity $neighborhood) { if ($neighborhood->getName() == null) { throw new \InvalidArgumentException("neighborhood.name may" . " not be null"); } /* * does the region already exist, if it does reset it in the neighborhood */ try { $region = $this->regionMapper()->getRegionByName($neighborhood->getRegion()->getName()); $neighborhood->setRegion($region); } catch (\Doctrine\ORM\NoResultException $e) { } if ($neighborhood->getDateTimeAdded() == null) { $neighborhood->setDateTimeAdded(date("Y-m-d H:i:s")); } $this->em->persist($neighborhood); $this->em->flush($neighborhood); }